You can create a new stream that accepts a list of people and a stream of keys, combines them and scans to filter the latter.
const keyup$ = Rx.Observable.fromEvent(_input, 'keyup') .map(ev => ev.target.value) .debounce(500); const people$ = Rx.Observable.of(people) .merge(keyup$) .scan((list, value) => people.filter(item => item.includes(value)));
This way you will have:
-L ------------------ list of people
------ k ----- k - k ---- keyups stream
-L ---- k ----- k - k ---- combined flow
Then you can scan it. As the docs say:
Rx.Observable.prototype.scan (battery, [seed])
Applies the battery function in the observed sequence and returns each intermediate result.
This means that you can filter the list by saving the new list to the battery.
Once you are subscribed, the data will be new.
people$.subscribe(data => console.log(data) );
Hope this helps / is clear enough.
source share