JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 46692
  • Score
    100M100P100Q165549F
  • License MIT

Allow add or remove redux middlewares dynamically

Package Exports

  • redux-dynamic-middlewares

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (redux-dynamic-middlewares) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

redux-dynamic-middlewares

Allow add or remove redux middlewares dynamically (for example: on route change).

npm install --save redux-dynamic-middlewares

Example

// configure store

import { createStore, applyMiddleware } from 'redux'
import rootReducer from './reducers/index'

import dynamicMiddlewares from 'redux-dynamic-middlewares'

const store = createStore(
  rootReducer,
  applyMiddleware(
    // ... other static middlewares
    dynamicMiddlewares
  )
)

// some other place in your code

import { addMiddleware, removeMiddleware, resetMiddlewares } from 'redux-dynamic-middlewares'

const myMiddleware = store => next => action => {
  // do something
  return next(action)
}

// will add middleware to existing chain
addMiddleware(myMiddleware /*[, anotherMiddleware ... ]*/)

// will remove middleware from chain (only which was added by `addMiddleware`)
removeMiddleware(myMiddleware)

// clean all dynamic middlewares
resetMiddlewares()