Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Composing Reactive Software

Composing Reactive Software

michaelavila

July 28, 2017
Tweet

More Decks by michaelavila

Other Decks in Programming

Transcript

  1. Agenda • Insufficient overview • Important, but poorly explained idea

    • Vague and unjustified conclusion • Questions
  2. interface Observable<T> { subscribe( onNext: (T) => void, onError: (Error)

    => void, onCompleted: () => void, ): Subscription; map( (T) => V): Observable<V>; flatMap((T) => Observable<V>): Observable<V>; scan( (V, T) => V, V): Observable<V>; filter( (T) => boolean): Observable<T>; withLatestFrom(Observable<V>, ...): Observable<[T, V, ...]>; combineLatest( Observable<V>, ...): Observable<[T, V, ...]>; … any many more! }
  3. Operators buffer bufferCount bufferTime bufferToggle bufferWhen combineAll combineLatest concat concatAll

    concatMap concatMapTo count debounce debounceTime defaultIfEmpty delay delayWhen dematerialize distinctUntilChanged do every expand filter first groupBy ignoreElements last let map mapTo merge mergeMap partition pluck publish race repeat retry retryWhen sample scan share single skip skipUntil skipWhile startWith switchMap window windowCount windowTime windowToggle windowWhen withLatestFrom zip … and probably more
  4. const email$ = Observable.fromEvent(...<input/>...); const password$ = Observable.fromEvent(...<input/>...); const login$

    = Observable.fromEvent(...<button/>...); const activeUser = login$ .withLatestFrom(email$, password$) .flatMap(([_, email, password]) => { return Observable.ajax.post('/auth/', { email, password }) .map(({ response }) => response); }); activeUser.subscribe(...<div>...);