Dynamic Middleware for Redux
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.
When creating your Redux
Store simple attach a
DynamicMiddleware object to it.
dynamicMiddleware = new DynamicMiddleware<State>.empty(); store = new Store<State>(reducer, middleware: [ dynamicMiddleware, ]);
Then add and remove middleware as you need.
dynamicMiddleware.add((store, action, next) => print("Hello World!") );
DynamicMiddleware.fromSingle constructor to create new dynamic middleware with a single instance of
store = new Store<State>(reducer, middleware: [ new DynamicMiddleware.fromSingle(middleware1), ]);
DynamicMiddleware.fromList constructor to create new dynamic middleware from a
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);
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.