Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: logicMiddleWare.removeLogic(logics) #155

Open
Hypnosphi opened this issue Sep 27, 2019 · 2 comments
Open

Feature request: logicMiddleWare.removeLogic(logics) #155

Hypnosphi opened this issue Sep 27, 2019 · 2 comments

Comments

@Hypnosphi
Copy link

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
Copy link
Author

Hypnosphi commented Sep 27, 2019

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

@erikroe
Copy link

erikroe commented Sep 22, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants