In my case, I have an access token, and should that token exist, I would return it as an observable of type string:
if (this.accessToken){
return of(this.accessToken);
}
Due to a recent update, I noticed that of
is deprecated with the following message:
of is deprecated: use scheduled instead 'scheduled([a, b, c], scheduler)' (deprecation)
The new syntax is quite verbose, would anyone know the equivalent scheduled
version of the same simple of
? The keyword name makes it difficult to search for information on it.
Thanks!
subscribe isn't deprecated, only the variant you're using is deprecated. In the future, subscribe will only take one argument: either the next handler (a function) or an observer object.
Observable JavaScript represents a progressive way of handling events, async the activity, and multiple values in JavaScript. These observables are just the functions that throw values and Objects known as observers subscribe to such values that define the callback functions such as error(), next() and complete().
RxJS' of() is a creational operator that allows you to create an RxJS Observable from a sequence of values. According to the official docs: of() converts the arguments to an observable sequence. For example: import { of } from 'rxjs'; of(1, 2, 3, 4) .
Java's Observer and Observable Are Deprecated in JDK 9. Around since Java 1.0, the Observable class will be deprecated in Java 9, as is the Observer interface. See how they've been replaced over time. by. Dustin Marx.
Additional details justifying the deprecation of Observable and Observer can be found in JDK-8154801 ("deprecate Observer and Observable"). There is a quote in there from Josh Bloch as part of JDK-4180466 ("Why is java.util.Observable class not serializable.") dated February 1999: This class is no longer under active development.
As per the post Java's Observer and Observable Are Deprecated in JDK 9 The event model supported by Observer and Observable is quite limited, the order of notifications delivered by Observable is unspecified, and state changes are not in one-for-one correspondence with notifications.
Why Observer is deprecated in Java 9? Ans: The Observable class and the Observer interface have been deprecated in Java 9 because the event model supported by Observer and Observable is quite limited, the order of notifications delivered by Observable is unspecified, and state changes are not in one-for-one correspondence with notifications.
Only the overloads that accept a scheduler are deprecated. The variant that you are using is not deprecated, see https://github.com/ReactiveX/rxjs/blob/master/src/internal/observable/of.ts
As said above, it is not deprecated.
I suppose you are migrating from RxJS v5 to RxJS v6. In that case:
The standard observable processing like of, map, filter, etc
Observable.of(1,2,3).map(x => 2 * x);
Becomes
import {of, map} from 'rxjs';
import {map} from 'rxjs/operators';
of(1,2,3).pipe(map(x => 2 * x));
Check more here https://www.learnrxjs.io/concepts/rxjs5-6.html
If you do have a scheduler, the equivalent for of(item, scheduler)
is scheduled([item], scheduler)
. If you're already passing in an array of items, you don't need the brackets.
@daniel-hilgarth is right but you can use following commands if you need to emulate of(1, 2, 3)
import {asapScheduler, scheduled} from "rxjs";
scheduled([1, 2, 3], asapScheduler);
or
import {asyncScheduler, scheduled} from "rxjs";
scheduled([1, 2, 3], asyncScheduler);
You can read more about asap here: https://rxjs.dev/api/index/const/asapScheduler
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With