Skip to content

Instantly share code, notes, and snippets.

@jorinvo
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jorinvo/b862d4a6dfd4ffb7e059 to your computer and use it in GitHub Desktop.
Save jorinvo/b862d4a6dfd4ffb7e059 to your computer and use it in GitHub Desktop.
miniflux
export default function bindActions (actions, render, initialState) {
var state = initialState
function update (updatedState) {
state = updatedState
render(state)
}
var boundActions = Object.keys(actions).reduce(function (o, name) {
o[name] = function () {
if (process.env.NODE_ENV !== 'production') {
console.info(`ACTION: "${name}"`)
}
actions[name].call(o, update, state, ...arguments)
}
return o
}, {})
if (process.env.NODE_ENV !== 'production') {
window.actions = boundActions
window.render = render
window.state = state
}
return boundActions
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment