-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
81 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,82 @@ | ||
# fusion-plugin-created | ||
# fusion-plugin-redux-thunk | ||
|
||
You have created a Fusion.js universakl plugin. | ||
Installs the [`redux-thunk`](https://github.com/reduxjs/redux-thunk) middleware for asynchronous dispatch. | ||
|
||
* Run linters: yarn lint | ||
* Run tests: yarn test | ||
* Build the plugin: yarn transpile | ||
--- | ||
|
||
### Table of contents | ||
|
||
* [Installation](#installation) | ||
* [Usage](#usage) | ||
* [Setup](#setup) | ||
* [API](#api) | ||
* [Registration API](#registration-api) | ||
|
||
--- | ||
|
||
### Installation | ||
```js | ||
yarn add fusion-plugin-redux-thunk | ||
``` | ||
|
||
### Usage | ||
|
||
Dispatch a thunk! | ||
|
||
```js | ||
const imAThunk = () => | ||
dispatch => { | ||
dispatch({ type: 'IM_A_THUNK' }); | ||
setTimeout(() => dispatch({ type: 'HES_A_THUNK' })); | ||
}; | ||
|
||
store.dispatch(imAThunk()); | ||
``` | ||
|
||
### Setup | ||
|
||
```js | ||
// main.js | ||
import React from 'react'; | ||
import Redux, { | ||
ReduxToken, | ||
ReducerToken, | ||
EnhancerToken, | ||
GetInitialStateToken, | ||
} from 'fusion-plugin-react-redux'; | ||
import ThunkEnhancer, { ThunkEnhancerToken } from 'fusion-plugin-redux-thunk'; | ||
import App from 'fusion-react'; | ||
import { createPlugin } from 'fusion-core'; | ||
import { compose } from 'redux'; | ||
import reducer from './reducer'; | ||
|
||
export default () => { | ||
const app = new App(root); | ||
app.register(ReduxToken, Redux); | ||
app.register(ReducerToken, reducer); | ||
app.register(ThunkEnhancerToken, ThunkEnhancer); | ||
app.register(EnhancerToken, createPlugin({ | ||
deps: { thunkEnhancer: ThunkEnhancerToken }, | ||
provides: ({ thunkEnhancer }) => compose(thunkEnhancer), | ||
})); | ||
__NODE__ && app.register(GetInitialStateToken, async ctx => ({})); | ||
} | ||
``` | ||
|
||
### API | ||
|
||
#### Registration API | ||
|
||
##### `ThunkEnhancer` | ||
```js | ||
import ThunkEnhancer from 'fusion-plugin-redux-thunk'; | ||
``` | ||
|
||
The `redux-thunk` enhancer. Installs redux middleware. Typically registed to [`ThunkEnhancerToken`](#thunkenhancertoken) | ||
|
||
##### `ThunkEnhancerToken` | ||
```js | ||
import { ThunkEnhancerToken } from 'fusion-plugin-redux-thunk'; | ||
``` | ||
|
||
Typically registered with [`ThunkEnhancer`](#thunkenhancer) |
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