This lesson introduces filter: an operator that allows us to let only certain events pass, while ignoring others.
var foo = Rx.Observable.interval(1000); /* --0--1--2--3--4--5--6--7- filter(x => x % 2 === 0) --0-----2-----4-----6---- */ var bar = foo.filter(x => x % 2 === 0); bar.subscribe( function (x) { console.log(‘next ‘ + x); }, function (err) { console.log(‘error ‘ + err); }, function () { console.log(‘done‘); }, );
时间: 2024-10-15 23:26:27