kenwheeler / mcfly

Flux architecture made easy
BSD 3-Clause "New" or "Revised" License
762 stars 46 forks source link

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

Open willpe opened 9 years ago

willpe commented 9 years ago

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:

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 commented 9 years ago

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 commented 9 years ago

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.