effector / effector/eslint-plugin
Rule: `prefer-clean-model-structure`
- Dominant language
- TypeScript
- Stars
- 94
- Forks
- 18
- PR merge metrics
- No merged PRs in 30d
Description
This rule should improve the readability of the code.
The rule should check the order of definitions of units:
1. First of all define domains
2. Define events
3. After events define derived events
4. Next define stores
5. After simple stores define derived stores
6. Next define effects
7. After effects define derived effects (`attach`)
8. After all definitions write logic on `sample`'s
9. Do not mix custom mapper/functions with samples and definitions, move them down
This rule should ban using `.on` and `.reset` etc. methods on stores immediately after definition. The same for domains, effects, and events.
This rule should not be auto-fixable, because it's affects business-logic.
#### FAIL
```ts
// prefer-clean-model-structure: 'error'
const someHappened = createEvent()
const $data = createStore(0)
.on(someHappened, (c) => c + 1)
const runMeFx = createEffect(() => {})
function calculate(a, b) {
return a + b;
}
sample({ clock: someHappened, target: runMeFx })
export const anotherFx = attach({
source: $data,
async effect(data, arg) {
return calculate(data, arg)
},
})
sample({ clock: anotherFx.doneData, target: someHappened })
```
#### OKAY
```ts
// prefer-clean-model-structure: 'error'
const someHappened = createEvent()
const $data = createStore(0)
const runMeFx = createEffect(() => {})
export const anotherFx = attach({
source: $data,
async effect(data, arg) {
return calculate(data, arg)
},
})
$data.on(someHappened, (c) => c + 1)
sample({ clock: someHappened, target: runMeFx })
sample({ clock: anotherFx.doneData, target: someHappened })
function calculate(a, b) {
return a + b;
}
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.