Last active
December 11, 2015 12:58
-
-
Save lauripiispanen/4603900 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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