Skip to content
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
flow-typed
src
.cuprc.js
.eslintrc.js
.flowconfig
.gitignore
Dockerfile
LICENSE
README.md
docker-compose.yml
package.json
renovate.json
yarn.lock

README.md

fusion-plugin-redux-thunk

Installs the redux-thunk middleware for asynchronous dispatch.

This is just for convenience, you can see an alternative here.


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

Alternative

// main.js
import React from 'react';
import Redux, {
  ReduxToken,
  ReducerToken,
  EnhancerToken,
  GetInitialStateToken,
} from 'fusion-plugin-react-redux';
import App from 'fusion-react';
import {applyMiddleware} from 'redux';
import thunk from 'redux-thunk';
import reducer from './reducer';

export default () => {
  const app = new App(root);
  app.register(ReduxToken, Redux);
  app.register(ReducerToken, reducer);
  app.register(EnhancerToken, applyMiddleware(thunk));
  __NODE__ && app.register(GetInitialStateToken, async ctx => ({}));
  return app;
}
You can’t perform that action at this time.