Last active
August 29, 2015 14:23
-
-
Save jorinvo/b862d4a6dfd4ffb7e059 to your computer and use it in GitHub Desktop.
miniflux
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
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