VoliJS / React-Type-R

Type-R Models binding to React
15 stars 3 forks source link

New stores API #12

Open gaperton opened 6 years ago

gaperton commented 6 years ago

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 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 commented 6 years ago

... 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. ...