From a3a0b39ca2729f428a5e1d5eb9e5c2b8ad4aa528 Mon Sep 17 00:00:00 2001 From: Aziz Khambati Date: Sat, 22 Jul 2017 15:05:13 +0530 Subject: [PATCH 1/5] Add createProvider docs --- docs/api.md | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/docs/api.md b/docs/api.md index e744319f4..37259f4df 100644 --- a/docs/api.md +++ b/docs/api.md @@ -384,3 +384,40 @@ function selectorFactory(dispatch) { export default connectAdvanced(selectorFactory)(TodoApp) ``` + +### `createProvider([storeKey])` + +Creates a new `` which will set the Redux Store on the passed key of the context. You probably only need this if you are in the inadvisable position of having multiple stores. You will also need to pass the same `storeKey` to the `options` argument of [`connect`](#connectmapstatetoprops-mapdispatchtoprops-mergeprops-options) + + +#### Arguments + +* [`storeKey`] (String): The key of the context on which to set the store. Default value: 'store' + +#### Examples +Before creating multiple stores, please go through this FAQ: [Can or should I create multiple stores?](http://redux.js.org/docs/faq/StoreSetup.html#can-or-should-i-create-multiple-stores-can-i-import-my-store-directly-and-use-it-in-components-myself) + +```js +import {connect, createProvider} from 'react-redux' + +const STORE_KEY = 'componentStore' + +export const Provider = createProvider(STORE_KEY) + +function connectExtended( + mapStateToProps, + mapDispatchToProps, + mergeProps, + options = {} +) { + options.storeKey = STORE_KEY + return connect( + mapStateToProps, + mapDispatchToProps, + mergeProps, + options + ) +} + +export {connectExtended as connect} +``` From 4fab075fa626112a147cc6b344d2406a6a4acceb Mon Sep 17 00:00:00 2001 From: Aziz Khambati Date: Sat, 22 Jul 2017 15:33:22 +0530 Subject: [PATCH 2/5] Add storeKey to connect options --- docs/api.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/api.md b/docs/api.md index 37259f4df..708576701 100644 --- a/docs/api.md +++ b/docs/api.md @@ -78,6 +78,7 @@ It does not modify the component class passed to it; instead, it *returns* a new * [`areOwnPropsEqual`] *(Function)*: When pure, compares incoming props to its previous value. Default value: `shallowEqual` * [`areStatePropsEqual`] *(Function)*: When pure, compares the result of `mapStateToProps` to its previous value. Default value: `shallowEqual` * [`areMergedPropsEqual`] *(Function)*: When pure, compares the result of `mergeProps` to its previous value. Default value: `shallowEqual` + * [`storeKey`] *(String)*: The key of the context from where to read the store. Default value: `"store"` ##### The arity of mapStateToProps and mapDispatchToProps determines whether they receive ownProps @@ -421,3 +422,4 @@ function connectExtended( export {connectExtended as connect} ``` +Now you can import the above `Provider` and `connect` and use them. From f424030d5b3e5d82b4980859bcf2066a4d7f7cc1 Mon Sep 17 00:00:00 2001 From: Aziz Khambati Date: Sat, 22 Jul 2017 15:34:09 +0530 Subject: [PATCH 3/5] italics --- docs/api.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api.md b/docs/api.md index 708576701..76d8087bb 100644 --- a/docs/api.md +++ b/docs/api.md @@ -393,7 +393,7 @@ Creates a new `` which will set the Redux Store on the passed key of t #### Arguments -* [`storeKey`] (String): The key of the context on which to set the store. Default value: 'store' +* [`storeKey`] (*String*): The key of the context on which to set the store. Default value: 'store' #### Examples Before creating multiple stores, please go through this FAQ: [Can or should I create multiple stores?](http://redux.js.org/docs/faq/StoreSetup.html#can-or-should-i-create-multiple-stores-can-i-import-my-store-directly-and-use-it-in-components-myself) From 0fd6d574393ccfe786ccd846d70a73f8be175749 Mon Sep 17 00:00:00 2001 From: Aziz Khambati Date: Sat, 22 Jul 2017 15:34:57 +0530 Subject: [PATCH 4/5] Update api.md --- docs/api.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/api.md b/docs/api.md index 76d8087bb..347da35a2 100644 --- a/docs/api.md +++ b/docs/api.md @@ -78,7 +78,7 @@ It does not modify the component class passed to it; instead, it *returns* a new * [`areOwnPropsEqual`] *(Function)*: When pure, compares incoming props to its previous value. Default value: `shallowEqual` * [`areStatePropsEqual`] *(Function)*: When pure, compares the result of `mapStateToProps` to its previous value. Default value: `shallowEqual` * [`areMergedPropsEqual`] *(Function)*: When pure, compares the result of `mergeProps` to its previous value. Default value: `shallowEqual` - * [`storeKey`] *(String)*: The key of the context from where to read the store. Default value: `"store"` + * [`storeKey`] *(String)*: The key of the context from where to read the store. Default value: `'store'` ##### The arity of mapStateToProps and mapDispatchToProps determines whether they receive ownProps @@ -393,7 +393,7 @@ Creates a new `` which will set the Redux Store on the passed key of t #### Arguments -* [`storeKey`] (*String*): The key of the context on which to set the store. Default value: 'store' +* [`storeKey`] (*String*): The key of the context on which to set the store. Default value: `'store'` #### Examples Before creating multiple stores, please go through this FAQ: [Can or should I create multiple stores?](http://redux.js.org/docs/faq/StoreSetup.html#can-or-should-i-create-multiple-stores-can-i-import-my-store-directly-and-use-it-in-components-myself) From 223aec5e853c3e1babfaac47d3a606e4ac626ee3 Mon Sep 17 00:00:00 2001 From: Aziz Khambati Date: Sat, 22 Jul 2017 15:36:36 +0530 Subject: [PATCH 5/5] Add you probably only need this --- docs/api.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api.md b/docs/api.md index 347da35a2..51c478c9e 100644 --- a/docs/api.md +++ b/docs/api.md @@ -78,7 +78,7 @@ It does not modify the component class passed to it; instead, it *returns* a new * [`areOwnPropsEqual`] *(Function)*: When pure, compares incoming props to its previous value. Default value: `shallowEqual` * [`areStatePropsEqual`] *(Function)*: When pure, compares the result of `mapStateToProps` to its previous value. Default value: `shallowEqual` * [`areMergedPropsEqual`] *(Function)*: When pure, compares the result of `mergeProps` to its previous value. Default value: `shallowEqual` - * [`storeKey`] *(String)*: The key of the context from where to read the store. Default value: `'store'` + * [`storeKey`] *(String)*: The key of the context from where to read the store. You probably only need this if you are in the inadvisable position of having multiple stores. Default value: `'store'` ##### The arity of mapStateToProps and mapDispatchToProps determines whether they receive ownProps