-
Notifications
You must be signed in to change notification settings - Fork 61
Refactor dispatch and getStore naming #203
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
Conversation
anacierdem
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks OK to me, just a few questions.
| .spyOn(Promise, 'reject') | ||
| .mockImplementation(() => {}); | ||
| it('should throw an error if contained store is used without container', () => { | ||
| const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this is not used anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is needed to silence React using console.error when we throw an error during render 😒
https://stackoverflow.com/a/66329699
| getStore = ( | ||
| Store, | ||
| scopeId = this.defaultScope, | ||
| config = { props: () => ({}), contained: () => false } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a heads up, if only one of them is provided (props or container) the other will not have a default as one might expect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, might check again how to improve it later, as with #201 we will likely add another key
| `Store ${Store.key} should be contained by a container but it is used globally. ` + | ||
| `While it might still work, it will likely cause unexpected behaviours.` | ||
| ) | ||
| if (Store.containedBy && !config.contained(Store)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not apparent to me why we pass in a predicate while we can already check the result at the call site?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, right now it is superfluous. I ported it from #201 where Store can be a different one but maybe we can evaluate at call site even there. Will check and eventually simplify in that PR.
A couple of minor improvements to help future developments (eg #201 ):
bindActionsarguments anddispatchcontext.getStoretoretrieveStoreto clarify API difference fromregistry.getStoreThere should be no public API changes as all this is internal stuff or unreleased