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

No warning if constant is null or handler is missing #272

Open
jhollingworth opened this issue Apr 10, 2015 · 3 comments
Open

No warning if constant is null or handler is missing #272

jhollingworth opened this issue Apr 10, 2015 · 3 comments

Comments

@jhollingworth
Copy link
Contributor

This code will produce the unhelpful error "TypeError: Cannot read property 'isActionCreator' of null "

var FooStore = Marty.createStore({
  handlers: {
    bar: null
  },
  bar() {
  }
});

and this code will cause the page to render nothing

var BarStore = Marty.createStore({
  handlers: {
    bar: "BAR"
  }
});

This is a regression as there used to be useful warnings for it

@taion
Copy link
Member

taion commented Apr 10, 2015

I took a quick look here. Some interesting things going on.

The null issue happens for an interesting reason. The current store implementation only validates the handlers in handleActions, so you don't even potentially get the warning until the first time something gets dispatched (rather than on store creation... but you can't really check on store creation because the base class constructor is invoked first, and handlers isn't currently static).

Then there's another interesting thing going on with

_.once(() => validateHandlers(this))

where as implemented, _.once really only does run that function once, even if it throws, and if it does throw, it will just keep returning undefined whenever you call it, which means that you only throw the ActionPredicateUndefinedError the first time, but then pass right through validateHandlers on subsequent calls, which gets you to the isActionCreator error.

The last wrinkle is that, because of the validation only getting invoked on action handling, if you have code that looks like the example here: http://martyjs.org/guides/queries/index.html, that catch will actually catch the exception thrown from this.dispatch, which then won't necessarily get logged out. Without it, the ActionPredicateUndefinedError does get logged (the first time, subsequent times log the error on isActionCreator).

@sporto
Copy link
Contributor

sporto commented May 5, 2015

I had an action with:

    this.dispatch(constants.NOTES_UPDATED, data);

NOTES_UPDATED was undefined. Marty would happily try to dispatch this. I would probably expect to see an error telling me that NOTES_UPDATED is undefined.

@jhollingworth
Copy link
Contributor Author

@sporto good point, I've just added a check for that

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

3 participants