-
-
Save Raynos/cdbcc26b4b1ad20b762b 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 foldp = require("signal/foldp") | |
var merge = require("signal/merge") | |
// accumulate :: [Signal<Function(S -> S)>] -> S -> Signal<S> | |
module.exports = accumulate | |
// accumulate take a list of signals of functions that take previous | |
// state and returns some new state and also takes the initial | |
// state. It will return a signal of the current state as applied | |
// by those functions | |
function accumulate(args, initial) { | |
return foldp(merge(args), function (state, fn) { | |
return fn(state) | |
}, initial) | |
} |
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 addMember = map(memberEvents, function (event) { | |
return function (state) { | |
var members = extend(state.members) | |
var value = event.value | |
var widget = Member(value, input) | |
membersHash[value.id] = value | |
members[value.id] = { | |
value: value | |
, elem: widget.view | |
} | |
return { | |
members: members | |
, currentWidget: widget | |
} | |
} | |
}) | |
var updateMember = map(modifyEvents, function (event) { | |
return function (state) { | |
var value = event.value | |
var members = extend(state.members) | |
var orig = members[value.id] | |
if (!orig) { | |
return { members: members } | |
} | |
members[value.id] = { | |
value: extend(orig.value, value) | |
, elem: orig.elem | |
} | |
return { members: members } | |
} | |
}) | |
var state = accumulate([ addMember, updateMember ], { | |
members: {} | |
, currentWidget: null | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment