redux-logic icon indicating copy to clipboard operation
redux-logic copied to clipboard

Feature request: `logicMiddleWare.removeLogic(logics)`

Open Hypnosphi opened this issue 6 years ago • 2 comments

I want to be able to add temporary logics, e.g. something that only applies while some particular React component is mounted. So ideally, I'd like to do something like that:

useEffect(() => {
  const logic = createLogic(...)
  logicMiddleware.addLogic([logic])
  return () => logicMiddleware.removeLogic([logic]) // missing API
}, [])

Hypnosphi avatar Sep 27 '19 18:09 Hypnosphi

My current workaround is to monkey-patch logicMiddleware object:

let logics = [...]
const logicMiddleware = createLogicMiddleware(logics)
const originalAddLogic = logicMiddleware.addLogic
logicMiddleware.addLogic = function addLogic(newLogics) {
  logics = logics.concat(newLogics)
  return originalAddLogic.apply(this, arguments)
}
logicMiddleware.removeLogic = function removeLogic(removedLogics) {
  logics = logics.filter(logic => !removedLogics.includes(logic))
  return this.replaceLogic(logics)
}

Hypnosphi avatar Sep 27 '19 19:09 Hypnosphi

Hello, I have a use-case where my application dynamically adds and also removes entire functionalities from my app while it runs. A "removeLogics" function is also what I am missing here to clean up not necessary checks. Even if this may be just an optimization I find this to be something required to round up the entire library.

erikroe avatar Sep 22 '20 14:09 erikroe