EBIA

Tag: filter

RxJS revisited

>> source

Flow Control Operators

filter, delay, debounceTime, take, takeUntil, distinct, distinctUntilChanged, throttleTime

throttleTime

Allow at most one click per second:

var button = document.querySelector('button');
Rx.Observable.fromEvent(button, 'click')
  .throttleTime(1000)
  .scan(count => count + 1, 0)
  .subscribe(count => console.log(`Clicked ${count} times`));

Value Producing Operators

pluck, pairwise, sample,

Simple RxJS Examples

import * as Rx from "rxjs";

let myArray = [1,2,'3','foo', 'bar', 'phi', 3,4,5, '7'];

let stream$ = Rx.Observable.interval(300).take(10)
    .map (x => parseInt(myArray[x]))
    .filter(x => !isNaN(x))
    .reduce((i,j) => {
    console.log(`Addition von ${i} mit ${j} = ${i+j}`);
    return i+j;
},0);

let result$ = stream$;

result$.subscribe(
    x => console.log(x),
    err => console.log(err),
    () => console.log ('done')
);

Copyright © 2020 EBIA

Theme by Anders NorenUp ↑