Reactive sequences

In notebook:
FrontEndMasters Async Javascript
Created at:
2016-09-21
Updated:
2016-09-21
Tags:
libraries Fundamentals
asynquence: Reactive Sequences

He tried many times, but never really got through the docs. 
He only uses a small subset. So... Asynquence 

He added reactive sequence to his library Asynquence. You can transparently go between the two.

It's the 5-6 most common methods, so only 2-3 Kb instead of 200.
 Example:
  function fromEvent(el, eventType) {
  return ASQ.react(function(proceed){
    $(el).bind(eventType,proceed);
  })
}
var rsq = fromEvent(btn, 'click');

rsq
  .val(function(evt){
    return evt.target.className;
  })
  .then(function(done,className){
    if(...){done(className)}
  })
  .val(function(className){
    console.log(className);
  });
​rsq​ :​ it's not exactly an observable, but a reactive sequence

he can put after ​rsq​ all the other methods of Asynquence (then, val, runner, etc.)

​ASQ.react​ to pump data into it

jQuery is of course optional

more precise syntax to pump data (​rsq.push​):
  function fromEvent(el, eventType) {
  var rsq = ASQ.react.of();
  $(el).bind(eventType, rsq.push);
  return rsq;
}
If reactive sequences, we can create operations to compose them together. 
  var rsq1 = fromEvent(btn, 'click'),
    rsq2 = fromEvent(inp, "keypress"),
    
    rsq3 = ASQ.react.all(rsq1,rsq2),
    rsq4 = ASQ.react.any(rsq1,rsq2);
    
rsq3.val(function(evt1,evt2){
  ...
})

rsq4.val(function(evt){
  ...
});
note ​.all​ (​zip​ in RxJS) and ​.any​ (​merge​ in RxJS)

Check on rx marbles how it works.