Created
March 20, 2018 04:37
-
-
Save vietduchelo/ffa380cb00a843b6ba22faae5ad6c7b2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Behavior Subject | |
// a is an initial value. if there is a subscription | |
// after this, it would get "a" value immediately | |
let bSubject = new BehaviorSubject("a"); | |
bSubject.next("b"); | |
bSubject.subscribe((value) => { | |
console.log("Subscription got", value); // Subscription got b, | |
// ^ This would not happen | |
// for a generic observable | |
// or generic subject by default | |
}); | |
bSubject.next("c"); // Subscription got c | |
bSubject.next("d"); // Subscription got d | |
Example 2 with regular subject: | |
// Regular Subject | |
let subject = new Subject(); | |
subject.next("b"); | |
subject.subscribe((value) => { | |
console.log("Subscription got", value); // Subscription wont get | |
// anything at this point | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment