Currently, version 7+ of RXjS is running where the team has declared many functions as deprecated and it has been decided to remove them completely in either version 8 or version 9.
So we should always show preparation for this so that we can work on the safe side in our current projects and in the future, we too can practice it.
There are many such functions which you are using daily but they are very popular functions and operators but RXjS team has declared them outdated, let us see some functions which you should stop using immediately.
Pluck
pluck selectively picks off a property from each emitted object in the observable sequence and returns an observable of the values of that particular property. pluck was a commonly used function that is being completely removed in RXjS version 8.
What will be the Solution?
You can use map function instead of pluck, here is an example
| map Example |
Simply you can use map function inside of pipe function to extract data from the Observable.
zip
I know you will miss this great function used in RXjS, every developer used once this function.
zip combines multiple observables together, emitting arrays of corresponding elements from each observable. It waits until all observables have emitted an item, then emits the combined array. zip function from rxjs/operators will be removed in RXjS v8.
What will be the Solution?
You can use zipWith function instead.
| zipWith example |
const zippedObservable = observable1.pipe(zipWith(observable2));
concat
concat concatenates multiple observables together, emitting the values from each observable one after the other, in the order they were passed. concat function will me removed in version 8 of RXjS.
What will be the Solution?
Use concatWith function instead to get same functionality like concat.
| concatWith example |
empty
empty creates an observable sequence that immediately completes without emitting any items. It's useful when you need an observable that does nothing but complete immediately.
empty was a very important function which we will have to lose in RXjS version 8.
What will be the Solution?
use EMPTY constant or scheduled function.
| EMPTY example |
EMPTY constant will help you to achieve many results and when you create a EMPTY variable it's type will be Observable<never>.
0 Comments