This rule should improve the readability of the code.
The rule should check the order of definitions of units:
- First of all define domains
- Define events
- After events define derived events
- Next define stores
- After simple stores define derived stores
- Next define effects
- After effects define derived effects (
attach)
- After all definitions write logic on
sample's
- 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
// 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
// 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;
}
This rule should improve the readability of the code.
The rule should check the order of definitions of units:
attach)sample'sThis rule should ban using
.onand.resetetc. 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
OKAY