effector / effector/eslint-plugin

Rule: `no-event-calls-in-reducers`

Open
#70 1 comment 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
TypeScript
Stars
94
Forks
18
PR merge metrics
No merged PRs in 30d

Description

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:
```ts
// 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: https://github.com/effector/effector/issues/541#issuecomment-954006684), so eslint-rule is preferred

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.