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

The whole future declared in a var

The whole future declared in a var

Reactive programming is a paradigm centered on one idea: to specify the dynamic behavior of a variable only at the declaration of that variable. The benefits of this are declarative programming and separation of concerns. In this talk we will explore Reactive programming in JavaScript.

This talk was given at dotJS 2015 in Paris.

André Staltz

December 07, 2015
Tweet

More Decks by André Staltz

Other Decks in Programming

Transcript

  1. var a = 3; var b = 10 * a;

    console.log(b); // 30 a = 4; console.log(b); // 30 b = 10 * a; console.log(b); // 40
  2. var a = 3; var b = 10 * a;

    console.log(b); // 30 a = 4; console.log(b); // 30 b = 10 * a; console.log(b); // 40
  3. var a = 3; var b = 10 * a;

    console.log(b); // 30 a = 4; console.log(b); // 30 b = 10 * a; console.log(b); // 40
  4. var a = 3; var b = 10 * a;

    console.log(b); // 30 a = 4; console.log(b); // 30 b = 10 * a; console.log(b); // 40
  5. var a = 3; var b = 10 * a;

    console.log(b); // 30 a = 4; b = 10 * a; console.log(b); // 40
 a = 6; b = 10 * a;
 console.log(b); // 60
  6. 3 4 6 a a = 3; a = 4;

    a = 6; b = 10 * a; b = 10 * a; b = 10 * a;
  7. b = 10 * a; b = 10 * a;

    b = 10 * a; updateB(a);
 updateB(a);
 updateB(a);
  8. 
 var a$ = Observable.of(3, 4);
 var b$ = a$.map(a

    => 10 * a);
 
 b$.subscribe(b => {
 console.log(b);
 });
 // 30
 // 40

  9. 
 var a$ = Observable.of(3, 4);
 var b$ = a$.map(a

    => 10 * a);
 
 b$.subscribe(b => {
 console.log(b);
 });
 // 30
 // 40

  10. 
 var a$ = Observable.of(3, 4);
 var b$ = a$.map(a

    => 10 * a);
 
 b$.subscribe(b => {
 console.log(b);
 });
 // 30
 // 40

  11. 
 var a$ = Observable.of(3, 4);
 var b$ = a$.map(a

    => 10 * a);
 
 b$.subscribe(b => {
 console.log(b);
 });
 // 30
 // 40

  12. 
 
 var b$ = a$.map(a => 10 * a);


    
 
 
 
 
 
 All future values 
 specified in the
 declaration
  13. 
 
 var b$ = a$.map(a => 10 * a);


    
 b$.set(60);
 
 
 
 

  14. 
 var a$ = Observable.of(3, 4);
 var b$ = a$.map(a

    => 10 * a);
 a$.set(6);
 b$.subscribe(b => {
 console.log(b);
 });
 // 30
 // 40

  15. 
 var a$ = Observable.of(3, 4, 6);
 var b$ =

    a$.map(a => 10 * a);
 
 b$.subscribe(b => {
 console.log(b);
 });
 // 30
 // 40
 // 60
  16. 
 var a$ = Observable.of(3, 4, 6);
 var b$ =

    a$.map(a => 10 * a);
 
 
 
 
 
 
 var click$ = Observable
 .fromEvent(document, ‘click’);
 
 
 
 
 
 

  17. 
 var click$ = Observable
 .fromEvent(document, ‘click’);
 var a$ =

    click$
 .scan((acc, ev) => acc + 1, 0);
 var b$ = a$.map(a => 10 * a);
 
 
 

  18. 
 var click$ = Observable
 .fromEvent(document, ‘click’);
 var a$ =

    click$
 .scan((acc, ev) => acc + 1, 0);
 var b$ = a$.map(a => 10 * a);
 
 
 

  19. 
 var click$ = Observable
 .fromEvent(document, ‘click’);
 var a$ =

    click$
 .scan((acc, ev) => acc + 1, 0);
 var b$ = a$.map(a => 10 * a);
 
 
 
 RxJS
  20. buffer catch combineLatest concat count debounce defaultIfEmpty delay distinctUntilChanged do

    elementAt every expand filter find first flatMap groupBy ignoreElements isEmpty last map max merge min multicast observeOn partition publish reduce refCount repeat retry sample scan share single skip skipUntil skipWhile startWith switch take takeUntil takeWhile throttle timeout window withLatestFrom zip
  21. function andreStaltz() { showSlide1(); showSlide2(); showSlide3(); // ... showLastSlide(); for

    (var i = 0; i < audience.length; i++) { audience[i].goGetCoffee(); }
 }