This lesson would teach you on another horizontal combination operator:buffer and its variants. Buffer groups consecutive values together, emitting the output as an array. The buffer variants and their arguments allow-specify when to close the buffers.
Buffer (Close observable): According to another observalbe to group items.
varFoo = Rx.Observable.of (' h ', ' e ', ' l ', ' l ', ' O '). zip (Rx.Observable.interval (Take (5), (x, y) =x);varBar = Rx.Observable.interval (in). Take (3);/*-----H-----E-----L-----L-----o| (foo)--------0--------1--------2| (bar) buffer (bar)--------H--------e--------ll|*/varresult =Foo.buffer (bar); Result.subscribe (function(x) {Console.log (' next ' +x); }, function(ERR) {console.log (' error ' +err); }, function() {console.log (' done ')); },); /*"Next H" "Next E" "next L,l" "Done"*/
BufferTime (number):
varFoo = Rx.Observable.of (' h ', ' e ', ' l ', ' l ', ' O '). zip (Rx.Observable.interval (Take (5), (x, y) =x);/*-----H-----E-----L-----L-----o| (foo)--------x--------x--------x| (900ms) bufferTime--------h--------e--------ll|*/varresult = Foo.buffertime (900); Result.subscribe (function(x) {Console.log (' next ' +x); }, function(ERR) {console.log (' error ' +err); }, function() {console.log (' done ')); },); /*"Next H" "Next E" "next L,l" "Done"*/
BufferCount (number):
varFoo = Rx.Observable.of (' h ', ' e ', ' l ', ' l ', ' O '). zip (Rx.Observable.interval (Take (5), (x, y) =x);/*-----H-----E-----L-----L-----o| (foo) bufferCount (2)----------([h,e])------([l,l]) ([o|]) L*/varresult = Foo.buffercount (2); Result.subscribe (function(x) {Console.log (' next ' +x); }, function(ERR) {console.log (' error ' +err); }, function() {console.log (' done ')); },); /*"Next H,e" "Next l,l" "Next O" "Done"*/
[RxJS] Transformation Operator:buffer, BufferCount, BufferTime