|
|
|
|
|
by ivansavz
3780 days ago
|
|
Very interesting write-up. Definitely cuts down on the boilerplate. Would be good to explain what `react-redux-provide` does under the hood. It might help convince redux users that the package is doing some of the work for them. Also what would the code look like without the @provide decorator? [Stick to ES6, it's already crazy enough, no need to jump to ES7 stuff] |
|
Short version:
- A provider has its own store (or it can share a store with other providers if you need it to).
- When you have a `propType` matching a provider's `actions`, those actions are automatically mapped to the store's dispatcher; so when you call `this.props.someAction`, it's essentially calling `provider.store.dispatch(provider.actions.someAction())`.
- And when you have a `propType` matching a provider's `reducers`, that component will always have the latest state of that reducer.
Without the `@provide` decorator, you would just `export default provide(SomeComponent)`. I've opted to use the ES7 decorator because it's cleaner, more concise, and immediately apparent.