Skip to content

Instantly share code, notes, and snippets.

@christianalfoni
Created February 5, 2016 08:46
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 christianalfoni/c9e91bad53a06948a2d3 to your computer and use it in GitHub Desktop.
Save christianalfoni/c9e91bad53a06948a2d3 to your computer and use it in GitHub Desktop.
FAQ: Why Cerebral does not provide context
/*
IT WAS SO NICE TO USE THE MODULE ARG
*/
// With context
function action ({module}) {
module.state.set('foo', 'bar');
}
// Now
function action ({state}) {
state.set('someModule.foo', 'bar');
}
// 1. Same number of chars (Though that is not a factor)
// 2. It is explicit in the action which module you are changing the state of
/*
NOW I HAVE TO HARDCODE WHICH MODULE I AM GOING TO USE
*/
// With context (moduleA.signals.signal)
[
changeSomeSate // changes moduleA
]
// With context (moduleB.signals.signal)
[
changeSomeState // change moduleB
]
// Now (moduleA.signals.signal)
[
changeSomeSate('moduleA') // changes moduleA
]
// Now (moduleB.signals.signal)
[
changeSomeState('moduleB') // change moduleB
]
// Now also (moduleA.signals.signal)
[
changeModuleAState // change moduleA
]
// Now also (moduleB.signals.signal)
[
changeModuleAState // change moduleA
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment