Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should verify both parameters are passed to McFly.createStore #34

Open
willpe opened this issue Feb 14, 2015 · 2 comments
Open

Should verify both parameters are passed to McFly.createStore #34

willpe opened this issue Feb 14, 2015 · 2 comments

Comments

@willpe
Copy link

willpe commented Feb 14, 2015

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 
@tomatau
Copy link
Contributor

tomatau commented Mar 9, 2015

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 :)

@willpe
Copy link
Author

willpe commented Mar 10, 2015

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants