note

event stream

const Observable = Rx.Observable;

const x = Observable.fromEvent(document.getElementById('button'), 'click')

x.forEach(y => alert('clicked'))

x.forEach(
  function onNext(e) {...},
  function onError(e) {...},
  function onCompleted() {...}
)

To unsubscribe:

const x = Observable.fromEvent(document.getElementById('button'), 'click')

const sub = x.forEach(function(e) {
  ...
  sub.dispose()
}

Stream transformation

const x = Observable.fromEvent(document.getElementById('button'), 'click');

const points = x.map(function (e) {
	return { x: e.clientX, y: e.clientY };
});

This is not triggering any operation as long as you don't consume it by calling .forEach.

Available operation on event streams

.scan

Like reduceon array, takes a function with accumulator as first parameter and the current item value in the second.

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

Flow control operators

TODO

  • filter --
  • delay
  • debounceTime
  • take
  • takeUntil
  • distinct
  • distinctUntilChanged

Value producing operators

  • pluck
  • pairwise
  • sample

About me

Stuff I do with my brain, my fingers and an editor:

(Front-end) development - typescript, Vue, React, svelte(kit) web architectures web performance API design pragmatic SEO security Accessibility (A11y) front-end dev recruitment and probably more...

Feel free to , check out my open source projects, or just read the things I write on this site.