This repository has been archived by the owner on Jan 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add createSubspaceProvider, mirroring Redux's createProvider.
Fixes #89
- Loading branch information
1 parent
3dceb86
commit bd313d7
Showing
8 changed files
with
187 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
# API Reference | ||
|
||
* [SubspaceProvider](/packages/react-redux-subspace/docs/api/SubspaceProvider.md) | ||
* [createSubspaceProvider](/packages/react-redux-subspace/docs/api/createSubspaceProvider.md) | ||
* [subspaced](/packages/react-redux-subspace/docs/api/subspaced.md) |
65 changes: 65 additions & 0 deletions
65
packages/react-redux-subspace/docs/api/createSubspaceProvider.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# `createSubspaceProvider([storeKey], [parentStoreKey])` | ||
|
||
A function that returns a new [SubspaceProvider](/packages/react-redux-subspace/docs/api/SubspaceProvider.md) which provides and consumes stores on the given context keys. `SubspaceProvider` itself is simply the result of calling `createSubspaceProvider()`. | ||
|
||
## Arguments | ||
|
||
1. `storeKey` (_string_): The context key to provide. The default is `store`, which is the default key that Redux's `connect` will look at. | ||
2. `parentStoreKey` (_string_): The context key to on which to look for a store. The default is `store`, which is the key provided by Redux's default Provider. | ||
|
||
## Examples | ||
|
||
Here is a basic example in which a subspace is provided on the 'subAppStore' key. This can be useful if you have a micro-frontend which will need to return rendering control to its parent, which will expect to have the root store defined on the `store` context key. | ||
|
||
```javascript | ||
import React from `react` | ||
import { createSubspaceProvider } from 'react-redux-subspace' | ||
import { connect } from 'react-redux' | ||
|
||
const SubspaceProvider = createSubspaceProvider('subAppStore') | ||
|
||
function MyComponent() { | ||
return ( | ||
<SubspaceProvider mapState={(state) => state.subApp}> | ||
<SubAppComponent /> | ||
</SubspaceProvider> | ||
) | ||
} | ||
|
||
let SubAppComponent = props => <span>{props.foo}</span>; | ||
|
||
function mapStateToProps(state) { | ||
return {foo: state.foo}; | ||
} | ||
|
||
const SubAppComponent = connect(mapStateToProps, null, null, {storeKey: 'subAppStore'})(SubAppComponent) | ||
``` | ||
|
||
This example consumes a root Redux store which is defined on a different context key, namely `rootStore`. | ||
|
||
```javascript | ||
import React from `react` | ||
import { createSubspaceProvider } from 'react-redux-subspace' | ||
import { connect, createProvider } from 'react-redux' | ||
|
||
const Provider = createProvider('rootStore'); | ||
const SubspaceProvider = createSubspaceProvider('subAppStore', 'rootStore'); | ||
|
||
function MyComponent() { | ||
return ( | ||
<Provider store={reduxStore}> | ||
<SubspaceProvider mapState={(state) => state.subApp}> | ||
<SubAppComponent /> | ||
</SubspaceProvider> | ||
</Provider> | ||
) | ||
} | ||
|
||
let SubAppComponent = props => <span>{props.foo}</span>; | ||
|
||
function mapStateToProps(state) { | ||
return {foo: state.foo}; | ||
} | ||
|
||
const SubAppComponent = connect(mapStateToProps, null, null, {storeKey: 'subAppStore'})(SubAppComponent) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.