{"library":"redux-replaceable-middleware","title":"Redux Replaceable Middleware","description":"Redux Replaceable Middleware is a utility that provides a mechanism to dynamically replace active Redux middleware instances at runtime. Published approximately 8 years ago, its current stable version is 1.1.0, and it appears to be abandoned, with no recent updates or active maintenance. This package was designed for earlier versions of Redux (specifically peer-depending on Redux v2, v3, or v4), and its core differentiation lies in enabling modification of the middleware chain after the Redux store has been created. In contrast, standard Redux practice involves defining the middleware chain once during store creation. Modern Redux applications, especially those using Redux Toolkit, typically manage asynchronous logic and side effects through patterns like Redux Thunk, Redux Saga, or Redux Toolkit's `createAsyncThunk` and listeners, rather than dynamic middleware replacement.","language":"javascript","status":"abandoned","last_verified":"Thu Apr 23","install":{"commands":["npm install redux-replaceable-middleware"],"cli":null},"imports":["const ReplaceableMiddleware = require('redux-replaceable-middleware');","const myReplaceableMiddleware = ReplaceableMiddleware();"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const Redux = require('redux');\nconst ReplaceableMiddleware = require('redux-replaceable-middleware');\n\n// A dummy reducer\nconst reducer = (state = { value: 0 }, action) => {\n  switch (action.type) {\n    case 'INCREMENT':\n      return { ...state, value: state.value + 1 };\n    case 'DECREMENT':\n      return { ...state, value: state.value - 1 };\n    default:\n      return state;\n  }\n};\n\n// Initial middleware (logs actions)\nconst loggingMiddleware = store => next => action => {\n  console.log('OLD Middleware: Dispatching', action.type, 'payload:', action.payload);\n  const result = next(action);\n  console.log('OLD Middleware: Next state', store.getState());\n  return result;\n};\n\n// Create the replaceable middleware instance\nconst replaceableMiddleware = ReplaceableMiddleware(loggingMiddleware);\n\n// Create the store with the replaceable middleware\nconst store = Redux.createStore(\n  reducer,\n  Redux.applyMiddleware(replaceableMiddleware)\n);\n\nconsole.log('Initial state:', store.getState());\nstore.dispatch({ type: 'INCREMENT' });\n\n// New middleware (adds a prefix to action type)\nconst newMiddleware = store => next => action => {\n  console.log('NEW Middleware: Pre-processing action', action.type);\n  const newAction = { ...action, type: `PREFIX_${action.type}` };\n  const result = next(newAction);\n  console.log('NEW Middleware: Post-processing action', newAction.type);\n  return result;\n};\n\nconsole.log('\\nReplacing middleware in 1 second...');\nsetTimeout(() => {\n  replaceableMiddleware.replaceBy(newMiddleware);\n  console.log('Middleware replaced! Dispatching again...');\n  store.dispatch({ type: 'DECREMENT' });\n  store.dispatch({ type: 'INCREMENT' });\n  console.log('Final state:', store.getState());\n}, 1000);\n","lang":"javascript","description":"This quickstart demonstrates how to initialize the Redux store with `redux-replaceable-middleware` and then dynamically swap out an active middleware at runtime. It shows an initial logging middleware being replaced by one that modifies action types. This example uses CommonJS syntax consistent with the package's age.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}