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

feature(store): catch action creators being passed to dispatch without () even sooner #2306

Merged
merged 2 commits into from
Jan 6, 2020
Merged

feature(store): catch action creators being passed to dispatch without () even sooner #2306

merged 2 commits into from
Jan 6, 2020

Conversation

alex-okrushko
Copy link
Member

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

During the recent merge of NgRx to Google I discovered a number of dispatch calls of new action creators without actual calls, e.g. store.dispatch(fooAction) instead of store.dispatch(fooAction()).

In NgRx we already added the runtime check, but I think we can do even better and catch it at compile time (IDEs will catch this too).

[ ] Bugfix
[x] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] Other... Please describe:

What is the current behavior?

Errors (warnings) at runtime

What is the new behavior?

Type Error: Functions are not allowed to be dispatched. Did you forget to call action creator?

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Other information

@ngrxbot
Copy link
Collaborator

ngrxbot commented Jan 4, 2020

Preview docs changes for 397ab6d at https://previews.ngrx.io/pr2306-397ab6d/

@erhise
Copy link
Contributor

erhise commented Jan 5, 2020

This is of insignificant importance to say the least but when I read Did you forget to call action creator? the first time I was a little bit confused for a second.

I wonder if the error message can be improved to something like

  • Did you forget to call the action creator function? or
  • Did you forget to make a function call?

Great feature however! 🎉

@alex-okrushko
Copy link
Member Author

@erhise
Thanks, adjusted for the better wording.

Copy link
Member

@timdeschryver timdeschryver left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Smart Alex 👍!

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

Successfully merging this pull request may close these issues.

4 participants