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

New stores API #12

Open
gaperton opened this issue May 11, 2018 · 1 comment
Open

New stores API #12

gaperton opened this issue May 11, 2018 · 1 comment
Assignees

Comments

@gaperton
Copy link

gaperton commented May 11, 2018

An existing context API will be phased out in v17, thus an approach to the stores need to be revised.

First, we will need to define the global Provider/Consumer pair for the store. Then, the component exposing the store need to inject render() method wrapper thus the store will be exposed. That's an easy part.

The store must be properly resolved in render() methods across the tree. There are two possible ways of achieving that.

  1. Wrap the consumer's render method.
  2. Create the wrapper component which will inject the store as prop. Like useStore( MyComponent ).

The second method is less magical and guarantees that the store lookup chain will be initialized properly.

The way how the store is defined might be changed as well. It can be:

  • The dedicated base class StoreComponent which uses the Store class as a base class for its state, and automatically exposes the state using the render() wrapping technique. We need to make sure that attributesIO endpoint skips members with empty endpoints.
  • The dedicated base class which uses separate members for the store and state as it is now.
  • The dedicated wrapper function exposing the store and injecting it into the component's prop. Like that: exposeStore( MyComponentStore, MyComponent ).

The last option will unify the usage of stores in parent and children components, and allow for integration of the store prefetch logic.

In general, HOF approach creating the wrapper components seems to be favorable.

@gaperton gaperton self-assigned this May 11, 2018
@gaperton
Copy link
Author

...
In fact, we're quite lucky that it's possible at all and won't introduce a lot of mess. It even makes things simpler.
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant