question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Why BehaviorSubject requires default value?

See original GitHub issue

I 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:closed
  • Created 9 years ago
  • Reactions:8
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

11reactions
akarnokdcommented, Jun 16, 2014

Hi. A parameterless create() has been already added to BehaviorSubject with v0.19.

7reactions
akarnokdcommented, Jun 7, 2017

You have the wrong repository then. I suggest asking question on their site or StackOverflow about this.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found