You often need-to-render out data before your stream begins from a click or another user interaction. This lessons shows how to use to startWith
set the initial output before you trigger your stream.
Const OBSERVABLE =Rx.observable;const Startbutton= Document.queryselector (' #start '); Const Stopbutton= Document.queryselector (' #stop '); Const start$= Observable.fromevent (Startbutton, ' click ')); Const interval$= Observable.interval (1000); Const stop$= Observable.fromevent (Stopbutton, ' click ')); Const intervalthatstops$=interval$. Takeuntil (stop$); const data= {count:0};start$. Switchmapto (intervalthatstops$). Startwith (data). Scan ((ACC)= { returnObject.assign (ACC, {count:acc.count + 1}). Subscribe ((x)= Console.log (x));
What Startwith would do be, before you click the Start button, it'll set the initial value for scan (), and logout 0 on th E screen.
Then if you click the Start button, it'll increase from 1 to ....
So it means Startwith actually would fire Subscrie once.
[RxJS] Displaying Initial Data with Startwith