The scan operator in RxJS is the main key to managing values and states in your stream. Scan behaves just as a reduce function would, but scan is able to collect values from streams over time. This lesson covers using startWith to set the initial accumulator value then using scan to update the value of the clock from the clicks and interval.
Here my quick fix to the example:
.startWith(new Date().toString())
and
.scan((acc, action) => {
let date = new Date(acc);
switch (action) {
case 'xyz':
date.setSeconds(date.getSeconds() + 1);
...
}
return date;
can I pass initial new date to scan function without using startWith.