fluxible-plugin-middleware
v0.1.1
Published
A plugin for Fluxible applications to provide an interface that attaches middlewares between an action dispatch and a store handler
Downloads
6
Maintainers
Readme
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));