Skip to main content

Action

Action is just a function with re-resolvable events, which makes them an important part of scenarios.

Example action
const increment = action(() => counter.set(current => current + 1));

setTimeout(increment, 100);

await increment.events.invoked;

console.log(`incremented after 100ms`);

Empty actions

Actions may be empty. When that's the case, they do nothing but emit invoked event when called, and this may be used to control a scenario flow.

Using empty actions to control scenarios
const increment = action();
const decrement = action();

scenario(increment.events.invoked, () => {
counter.set(current => current + 1);
});

scenario(decrement.events.invoked, () => {
counter.set(current => current - 1);
});