0.1.1 • Published 9 years ago

fluxible-plugin-middleware v0.1.1

Weekly downloads
4
License
MIT
Repository
github
Last release
9 years ago

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));