fusion-plugin-redux-thunk
v0.1.1
Published
FusionJS plugin for redux-thunk
Downloads
6
Readme
fusion-plugin-redux-thunk
Installs the redux-thunk
middleware for asynchronous dispatch.
Table of contents
Installation
yarn add fusion-plugin-redux-thunk
Usage
Dispatch a thunk!
const imAThunk = () =>
dispatch => {
dispatch({ type: 'IM_A_THUNK' });
setTimeout(() => dispatch({ type: 'HES_A_THUNK' }));
};
store.dispatch(imAThunk());
Setup
// 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
import ThunkEnhancer from 'fusion-plugin-redux-thunk';
The redux-thunk
enhancer. Installs redux middleware. Typically registed to ThunkEnhancerToken
ThunkEnhancerToken
import { ThunkEnhancerToken } from 'fusion-plugin-redux-thunk';
Typically registered with ThunkEnhancer