dynamic_middleware 0.5.1
dynamic_middleware: ^0.5.1

Dart 2 incompatible

A way to define middleware for redux dynamically

Dynamic Middleware for Redux #

Build Status

Dart library that allows adding and removing Redux middleware after a Redux Store has already been initialized.

Warning: Some might say that doing this breaks the contract of idempotency you typically have with a Redux store. They're right! There are, however, some instances where this is useful. This library was created to support a new type of Redux store that is not idempotent.

Usage #

When creating your Redux Store simple attach a DynamicMiddleware object to it.

dynamicMiddleware = new DynamicMiddleware<State>.empty();
store = new Store<State>(reducer, middleware: [

Then add and remove middleware as you need.

dynamicMiddleware.add((store, action, next) => 
    print("Hello World!")

Use the DynamicMiddleware.fromSingle constructor to create new dynamic middleware with a single instance of Middleware.

store = new Store<State>(reducer, middleware: [
    new DynamicMiddleware.fromSingle(middleware1),

Use the DynamicMiddleware.fromList constructor to create new dynamic middleware from a List of Middleware.

waresList = <Middleware<State>>[middleware1, middleware2];
store = new Store<State>(reducer, middleware: [
    new DynamicMiddleware.fromList(waresList),

Adding and Removing Middleware #

Add a single piece of middleware.

void add(Middleware<State> middleware);

Add a List of middleware.

void addAll(List<Middleware<State>> middleware) => middlewares.addAll(middleware);

Remove a single piece of middleware.

void remove(Middleware<State> middleware) => middlewares.remove(middleware);

Remove all middleware previously added.

void clear();