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

Rule: no-event-calls-in-reducers #70

Open
AlexandrHoroshih opened this issue Oct 29, 2021 · 1 comment
Open

Rule: no-event-calls-in-reducers #70

AlexandrHoroshih opened this issue Oct 29, 2021 · 1 comment
Labels
enhancement New feature or request

Comments

@AlexandrHoroshih
Copy link
Member

Event or effect calls inside reducers or other supposed-to-be-pure functions like fn of sample or combine rule is a violation of current declared rules of effector, because it makes those functions calls observable "from the outside"

So code like this is technically wrong:

// this code must be either rewritten to operators or written in the same way, but inside `.watch`
$store.on(someEvent, (state, payload) => { 
 // store reducer meant to update stored value
 if (payload.some) {
   // but there is some control flow happening instead, which is wrong
   someEffect(state)
 } else {
  someOtherEvent(payload)
 }
 // next state is never returned - plain wrong usage of `.on`
})

Even though effector still can handle that, breaking this rule may lead to problems in next releases of effector

It looks like that check for such calls at the core adds more issues than profit (see: effector/effector#541 (comment)), so eslint-rule is preferred

@igorkamyshev
Copy link
Member

Yeah, good idea. I think we also should ban effects.

related #6

@igorkamyshev igorkamyshev added the enhancement New feature or request label Nov 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants