Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const render$ = new Subject()
- render$.subscribe(
- value => output.textContent = '' + value
- );
- // Just a source that increments a number over time when
- // you click buttons.
- const source$ = render$.pipe(
- startWith(INITIAL_VALUE),
- switchMap(initialValue => (
- merge(
- // when we click "+ 1" it adds `1`
- add1Click$.pipe(map(() => 1)),
- // when we click "+ 2" it adds `2`
- add2Click$.pipe(map(() => 2)),
- )
- .pipe(
- // A reducer to accumlate our number
- scan((acc, n) => acc + n, initialValue || 0),
- )
- )),
- // Start with 0, so we have an initial value to display
- startWith(INITIAL_VALUE),
- );
- // Here we're adding our custom `undo` and subscribing to it.
- source$.pipe(
- // "Undo" whenever we click the "Undo" button.
- undo(undoClick$, redoClick$),
- ).subscribe(render$);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement