Skip to content

Instantly share code, notes, and snippets.

@lauripiispanen
Last active December 11, 2015 12:58
Show Gist options
  • Save lauripiispanen/4603900 to your computer and use it in GitHub Desktop.
Save lauripiispanen/4603900 to your computer and use it in GitHub Desktop.
var Bacon = require('baconjs').Bacon,
_ = require('underscore'),
add = new Bacon.Bus,
remove = new Bacon.Bus,
compose = function(fn) {
return function (val) {
return function(ctx) {
return fn(ctx, val);
}
}
},
concat = function(arr, val) {
return arr.concat(val);
},
list = add
.map(compose(concat)) // --> concat(list, val);
.merge(remove.map(compose(_.without)))
.scan([], function(list, op) {
return op(list);
});
list.onValue(console.log);
add.push("a");
add.push("b");
add.push("c");
remove.push("b");
// outputs
[]
[ 'a' ]
[ 'a', 'b' ]
[ 'a', 'b', 'c' ]
[ 'a', 'c' ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment