Hello in this tutorial, we will go over BehaviorSubjects. They are a special type of Observable that we can subscribe to, to get the last value it was set it.
Hello in this tutorial, we will go over BehaviorSubjects. They are a special type of Observable that we can subscribe to, to get the last value it was set it.
Syntax
Subscribing to Detect Changes
myBehaviorSubject.subscribe(
The value parameter represents the new value that it was set last. The anonymous callback function is called every time we make a call to the next() function.
Updating the Value
To trigger the callback function from myBehaviorSubject.subscribe(), grab the BehaviorSubject object and then call the next() function. Inside the function, pass in the new value you want it to return.
myBehaviorSubject.next([some_value]);
Example
gameEndedListener = new BehaviorSubject<Boolean>(false);
In the example, there is a listener call gameEndedListener that listens for a change in the Boolean value that was passed in.