Skip to content

Latest commit

 

History

History
32 lines (26 loc) · 649 Bytes

no-guard.md

File metadata and controls

32 lines (26 loc) · 649 Bytes

effector/no-guard

Any guard call could be replaced with sample call.

// 👎 could be replaced
guard({ clock: trigger, soruce: $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.

// 👎 could be replaced
guard({
  clock: trigger,
  soruce: $data.map((data) => data.length),
  filter: Boolean,
  target: reaction,
});

// 👍 makes sense
sample({
  clock: trigger,
  soruce: $data,
  filter: Boolean,
  fn: (data) => data.length,
  target: reaction,
});