JSPM

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

Allow add or remove redux middlewares dynamically

Package Exports

  • redux-dynamic-middlewares
  • redux-dynamic-middlewares/lib/index.js

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

ℹ️ If you are building big redux app see redux-dynamic.

npm version npm downloads

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

npm install --save redux-dynamic-middlewares

Example

common usage:

// 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()

complex usage (when need many instances):

// configure store

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

import { createDynamicMiddlewares } from 'redux-dynamic-middlewares'

const dynamicMiddlewaresInstance = createDynamicMiddlewares()

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

// some other place in your code

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

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

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

// clean all dynamic middlewares
dynamicMiddlewaresInstance.resetMiddlewares()