-
-
Notifications
You must be signed in to change notification settings - Fork 244
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
Forbid imperative calls of effector units from reducers #541
Comments
I guess, it can be implemented in the same way scopes work 🤔 let pureContext = false
const runPure = (cb, ...args) => {
pureContext = true
cb(...args)
pureContext = false
}
...
// somewhere in `launch`
if (pureContext) {
throw Error(...)
} |
Should we really add this to core package? I think it can be implemented through effector/eslint-plugin |
Sure, it can (and, i guess, should) be implemented as eslint-plugin rule too, but it won't be as reliable as actual check at the core + not all projects using this eslint-plugin So, i think, it is better if plain-wrong practices like in the example are prevented at the core level |
There may be some edge cases as event calls may be deeply reordered before execution, not even mention events called from watchers during execution of the forbidden event call, so runtime error may appear in entirely irrelevant places of code I would rather prefer an eslint rule |
@zerobias What about to add some extra parameter to a And in the appropriate switch/case check it only if parameter is it could shoot me in the foot? |
@sergeysova well, looks like it should work in that way, let's try 👌 |
also add forgotten third argument to step functions related issue #541
related issue #541 this commit should fail
Deprecation warning will be published in the next minor release |
But what if I want to create an effect which triggers 2 effects which are expected to be done together?
If we write this way we get the warning in console as well |
There should be no warning in your case, it’s valid usage |
Proposal
Throw error or show a console warning, if event or effect have been manually called from inside of store reducer or other pure functions.
Currently
effector
does not forbid or warn about event or effect calls inside reducers or other supposed-to-be-pure functions likefn
of sample orcombine
ruleBut, as it can be seen at effector telegram chat, many people do call events from reducers sometimes (and sometimes for a really long time) and have no clue, that it is not how it supposed to work.
Even though effector, apparently, still can handle that, using events this way goes way too much aganist declared rules and some projects may found themselves absolutely incompatible with some future release of effector
I think, explicit warning (or even exception) like
will help a lot here
Use case
Today an effector user shared the way he has been using
.on
for a long time - it was something like this:From his words, he was using effector like that from the very beginning and have not seen any problems yet.
Obviously, all of it mentioned in the documentation, but it looks like that sometimes people do not read it carefully enough and little push is needed
The text was updated successfully, but these errors were encountered: