Skip to content

effector/no-guard โ€‹

Any guard call could be replaced with sample call.

ts
// ๐Ÿ‘Ž could be replaced
guard({ clock: trigger, source: $data, filter: Boolean, target: reaction })

// ๐Ÿ‘ makes sense
sample({ clock: trigger, source: $data, filter: Boolean, target: reaction })

Nice bonus: sample is extendable. You can add transformation by fn.

ts
// ๐Ÿ‘Ž could be replaced
guard({
  clock: trigger,
  source: $data.map((data) => data.length),
  filter: Boolean,
  target: reaction,
})

// ๐Ÿ‘ makes sense
sample({
  clock: trigger,
  source: $data,
  filter: Boolean,
  fn: (data) => data.length,
  target: reaction,
})

Last updated:

Released under the MIT License