redux-logic
redux-logic copied to clipboard
Feature request: `logicMiddleWare.removeLogic(logics)`
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
}, [])
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)
}
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.