Skip to content

Migrate command emit to effects

Ignite Element now treats commands as intent triggers and effects as the place where state transitions produce DOM events.

const registerToggle = igniteCore({
source: machine,
events: (event) => ({
toggled: event<{ isOn: boolean }>(),
}),
commands: ({ actor, emit }) => ({
toggle: () => {
actor.send({ type: "TOGGLE" });
emit("toggled", { isOn: true });
},
}),
});
const registerToggle = igniteCore({
source: machine,
events: (event) => ({
toggled: event<{ isOn: boolean }>(),
}),
commands: ({ actor }) => ({
toggle: () => {
actor.send({ type: "TOGGLE" });
},
}),
effects: ({ snapshot, prevSnapshot, emit }) => {
if (snapshot.matches("on") === prevSnapshot.matches("on")) return;
emit("toggled", { isOn: snapshot.matches("on") });
},
});
  1. Remove emit from the commands parameter list.
  2. Keep commands limited to actor/store/observable intent.
  3. Add an effects callback and destructure only the fields you use.
  4. Compare state before emitting, such as snapshot with prevSnapshot.
  5. Keep your events map so emit stays typed.

From the repo root:

Terminal window
node scripts/migrate-emit-to-effects.mjs

The script reports files that still:

  • destructure emit in commands
  • call emit(...) in code that likely needs migration

Use --report <path> to save the output to a file.

emit has been removed from command context. Commands still receive { actor, command, host }; typed event emission belongs in effects().

  • Migration tooling and docs remain available to help with old command emit patterns.
  • effects() is now the supported path for typed event emission.