Last active
April 5, 2024 14:02
-
-
Save j-ulrich/55cdad6589f662c6a0a7b8228523968a to your computer and use it in GitHub Desktop.
ThinkRX: next'ing a ReplaySubject within a subscription to that ReplaySubject emits value immediately
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
const { rxObserver } = require('api/v0.3'); | |
const { ReplaySubject } = require('rxjs'); | |
const myReplaySubj = new ReplaySubject(); | |
myReplaySubj.next(1); | |
myReplaySubj.next(2); | |
myReplaySubj.next(3); | |
let didEmitNewValues = false; | |
const thinkRx = rxObserver(); | |
myReplaySubj.subscribe((val) => { | |
thinkRx.next(val); // Draw value in diagram | |
if(!didEmitNewValues) { | |
didEmitNewValues = true; | |
myReplaySubj.next(4); | |
myReplaySubj.next(5); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Link to ThinkRX: https://thinkrx.io/gist/55cdad6589f662c6a0a7b8228523968a/