NoNameProvided
NoNameProvided

Reputation: 8987

How get last item pushed to a RxJs/BehaviorSubject by value?

I am using rxjs in a project, the problem I face is that both myBehaviorSubject.value and myBehaviorSubject.getValue() returns the last item pushed into the observable by reference. Can I somehow get that last item by value?

Note: I know I can copy the object with Object.assign but that seems like boilerplate code to me. I am looking for some official method or piece of code what extends it to support this functionality. So what I want to do is something like myBehaviorSubject.getValueByValue() (Sounds strange, I know.)

Upvotes: 1

Views: 1009

Answers (1)

Matt Burnell
Matt Burnell

Reputation: 2796

No, there is nothing in rxjs that does this, and this isn't really in the Rx domain. While observables work best when used with immutable types, rxjs doesn't provide any features in this area. For simple object cloning you can, as you suggest, use something like Object.assign. For collections, I recommend immutable.js. You can (as suggested in the comments) extend BehaviorSubject yourself to include whichever implementation you prefer.

Upvotes: 1

Related Questions