Practical JavaScript reactive programming

Reactive programming is a coding style, when you operate with streams of events, as with usual consistent data.

So what the reason here to invent new approaches and libraries? The reason is the same, why we use promises: as much as possible avoid callbacks, working with asynchronous code. But in case of events we can’t use promises, because of it’s design:

1
2
3
4
5
6
var EE = require('events').EventEmitter;
var ee = new EE;
ee.on('some event', () => {
console.log('Triggered');
});
ee.emit('some event');

We can’t controll the moment of executing function and it doesn’t follow callbacks convention.

Practice

The most common use cases of event streams probably are throttle and debounce. Here a small playground to imagine them.