Skip to content

Latest commit

 

History

History
38 lines (30 loc) · 1 KB

strict-effect-handlers.md

File metadata and controls

38 lines (30 loc) · 1 KB

effector/strict-effect-handlers

Related documentation

When effect calls another effects then it should call only effects, not common async functions and effect calls should have await:

// 👍 effect without inner effects:
const delayFx = createEffect(async () => {
  await new Promise((rs) => setTimeout(rs, 80));
});
const authUserFx = createEffect();
const sendMessageFx = createEffect();

// 👍 effect with inner effects
const sendWithAuthFx = createEffect(async () => {
  await authUserFx();
  await delayFx();
  await sendMessageFx();
});
// 👎 effect with inner effects and common async functions

const sendWithAuthFx = createEffect(async () => {
  await authUserFx();
  //WRONG! wrap that in effect
  await new Promise((rs) => setTimeout(rs, 80));
  //context lost
  await sendMessageFx();
});

So, any effect might either call another effects or perform some async computations but not both.