mcfly
mcfly copied to clipboard
Should verify both parameters are passed to `McFly.createStore`
Recently had a store that, at least initially, handled no actions. when creating it, I wrote this:
var ConfigStore = McFly.createStore({
get: function(key){
if(!_config[key]){
console.warn("Config key '" + key + "' doesn't exist.");
}
return _config[key];
}
});
Everything worked, so I assumed I was allowed to ignore the second param to createStore
.
A little later, after I'd forgotten about this, I popped open the console in chrome and saw a fairly nasty stack trace coming out of the dispatcher. A couple hours of hunting later, I discovered my mistake.
It would be great if either:
- When no callback is specified, an error is thrown stating that the callback is a mandatory parameter
- When no callback is specified, a default, empty callback is substituted.
Will fork and submit a PR this weekend.
Stack:
TypeError: undefined is not a function
at Dispatcher.$Dispatcher_invokeCallback
at Dispatcher.dispatch
at
at $$$internal$$initializePromise
at new $$es6$promise$promise$$Promise
at
at $$$internal$$tryCatch
at $$$internal$$invokeCallback
at
at MutationObserver.$$asap$$flush
Why use a Store with no callback? In this situation I think it would be advisable to just expose a normal object.
Although I agree some feedback on a missing callback would be better :)
you're right, @tomatau - it doesn't really make any sense to have a store with no callback. Feedback would be nice to let you know you did something weird.