Skip to content

Instantly share code, notes, and snippets.

@j-ulrich
Last active April 5, 2024 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save j-ulrich/55cdad6589f662c6a0a7b8228523968a to your computer and use it in GitHub Desktop.
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
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);
}
});
@j-ulrich
Copy link
Author

j-ulrich commented Apr 5, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment