Why BehaviorSubject requires default value?
See original GitHub issueI often need BehaviorSubject that don’t have default value and should not spawn values until first value is supplied.
Currently as a workaround I initialize it with null and provide access to it after filter that ignores null value. Which looks ugly.
private BehaviorSubject<Location> locationUpdateSubject = BehaviorSubject.create((Location) null);
public Observable<Location> getLocationUpdates() {
return locationUpdateSubject.filter(new Func1<Location, Boolean>() {
@Override
public Boolean call(Location location) {
return location != null;
}
});
}
Issue Analytics
- State:
- Created 9 years ago
- Reactions:8
- Comments:13 (6 by maintainers)
Top Results From Across the Web
Give BehaviorSubject initial value - value being an Observable
I would do it like private user = new BehaviorSubject<User>(null); public user$ = this.user.asObservable(); constructor() { this.
Read more >BehaviorSubject - RxJS Reference - InDepth.Dev
This current value is either the item most recently emitted by the source observable or a seed/default value if none has yet been...
Read more >BehaviorSubject vs ReplaySubject(1) -beware of edge cases
A variant of Subject that requires an initial value and emits its current value whenever it is subscribed to. ReplaySubject. A variant of...
Read more >BehaviorSubject - Learn RxJS
Requires an initial value and emits the current value to new subscribers ; If you want the last emitted value(s) on subscription, but...
Read more >BehaviorSubject (RxJava Javadoc 3.1.5) - ReactiveX
The BehaviorSubject does not support clearing its cached value (to appear empty again), however, the effect can be achieved by using a special...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi. A parameterless create() has been already added to BehaviorSubject with v0.19.
You have the wrong repository then. I suggest asking question on their site or StackOverflow about this.