Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
342 views
in Technique[技术] by (71.8m points)

javascript - Simple way to get the current value of a BehaviorSubject with rxjs5

Previously in rxjs4 there was a method in the BehaviorSubject called: getValue() (doc here).

This method does not exist anymore in rxjs5.

So the only solution that I found to get the value of a BehaviorSubject was:

let value;
myBehaviorSubject.take(1).subscribe( (e) => value = e );

This code runs synchronously (I do not exactly understand why, but it does ...) and gets the value. It works, but it's not as clean as it could be if getValue() was present:

let value = myBehaviorSubject.getValue();

Why getValue() was removed in rxjs5 and what's the cleanest solution to this problem?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

As was pointed out by artur grzesiak in the comments, the BehaviorSubject interface was cleaned up, and the getter is now just myBehaviorSubject.value.

I just wanted to add this as an answer because I almost didn't read the comments to the original question, and would have missed the correct answer.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...