// Hooks
r03
Side effects on entry
Fire a side effect every time the machine arrives at a state — log it, persist it, page someone — without scattering checks across your call sites.
Code
order.hook_entry('shipped', () => {
analytics.track('order.shipped', { id });
email.shipping(customer);
});
order.hook_entry('delivered', closeOut);
Notes
Hooks run after the transition lands, never before — so you never fire order.shipped on a request that gets rejected. The machine is the source of truth; the side effects follow.