One of key features of spread is an ability to skip updates for some targets, but it requires object mutation or weird conditionals (it becomes worse when amount of targets grows):
sample({
clock: trigger,
fn: upd => upd.both
? ({foo: 0, bar: 0})
: ({foo: 0})
target: spread({
foo,
bar,
})
})
// or
sample({
clock: trigger,
fn(upd) {
const result = {foo: 0}
if (upd.both) {
result.bar = 0
}
return result
},
target: spread({
foo,
bar,
})
})
We can add special token SKIP which will mean that this unit will not be triggered:
import {spread, SKIP} from 'patronum'
// or maybe spread.SKIP
sample({
clock: trigger,
fn: upd =>({
foo: 0,
bar: upd.both ? 0 : SKIP
}),
target: spread({
foo,
bar,
})
})
One of key features of spread is an ability to skip updates for some targets, but it requires object mutation or weird conditionals (it becomes worse when amount of targets grows):
We can add special token SKIP which will mean that this unit will not be triggered: