Exercise
- Open exercise on codesandbox.
I've already imported the
ReplaySubjectclass and the necessary operator functions. - Create a new ReplaySubject and specify the generic type
number. - Use the
fromEventcreation operator to add an event listener to both theaddandsubbuttons. Within thepipe()for each mouse event use themap()operator to map to either1or-1appropriately. Finally, subscribe to both event listener Observables and set theReplaySubjectinstance as the Observer. - Use the
EventTarget.addEventListenerto add a click event listener to thecalcbutton. - In the callback function, subscribe to the
ReplaySubjectinstance. Within thepipe()use thescan()operator to sum the next notifications values. Within thesubsribe()method set thevalueproperty for thesuminput element to the next notification value emitted.