A plugin for Fluxible applications to provide an interface for attaching middlewares
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
LICENSE
README.md
index.es6
index.js
package.json

README.md

Middleware Plugin for Fluxible

A plugin for Fluxible applications to provide an interface that attaches middlewares between an action dispatch and a store handler. Highly inspired by Redux middlewares.

Install

npm install fluxible-plugin-middleware

Usage

import middlewarePlugin from "fluxible-plugin-middleware";
import Fluxible from "fluxible";

const app = new Fluxible();

const logMiddleware = function(actionContext){
    return function(next) {
      return function(type, payload){
        console.log(actionContext);
        console.info(type, payload);
        next(type, payload);
      };
    };
};

app.plug(middlewarePlugin(logMiddleware));

Now, when calling the context.dispatch method within action creators, all action objects will pass through the middlewares before getting dispatched into the stores for handling.

Your middlewares will also have access to the entire actionContext so you can fire the context functions within your middlewares if you like.

For additional middlewares:

app.plug(middlewarePlugin(logMiddleware, secondMiddleware, thirdMiddleware));