Skip to content

Conversation

@albertogasparin
Copy link
Collaborator

A couple of minor improvements to help future developments (eg #201 ):

  • refactor bindActions arguments and dispatch
  • rename context.getStore to retrieveStore to clarify API difference from registry.getStore
  • throw sync containedBy errors if env does not support scheduling (eg jsdom)
  • refactor getStore options to be easier to expand

There should be no public API changes as all this is internal stuff or unreleased

Copy link

@anacierdem anacierdem left a 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(() => {});

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.

Copy link
Collaborator Author

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 }

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.

Copy link
Collaborator Author

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

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?

Copy link
Collaborator Author

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.

@albertogasparin albertogasparin merged commit 17183b6 into master May 24, 2023
@albertogasparin albertogasparin deleted the fix/refactor-dispatch branch May 24, 2023 14:26
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.

3 participants