Detalhes do pacote

redux-dynamic-middlewares

pofigizm259.4kMIT2.2.0

Allow add or remove redux middlewares dynamically

redux, dynamic, middleware

readme (leia-me)

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

changelog (log de mudanças)

2.0.0 (2020-01-10)

  • [braking changes] The (store) => function of middleware will be run once

1.0.0 (2018-10-07)

  • Added possibility to use many instances (complex usage)
    import { createDynamicMiddlewares } from 'redux-dynamic-middlewares'
    

0.5.0 (2018-08-28)

  • use full store

0.4.0 (2018-01-24)

  • add LICENSE

0.3.0 (2018-01-07)

  • Added error message when try to remove unexisted middleware (@ali-master)
  • Updated build configuration

0.2.1 (2017-10-30)

  • add tests

0.1.3 (2017-04-01)

  • lib folder