Migrate command emit to effects
Ignite Element now treats commands as intent triggers and effects as the place where state transitions produce DOM events.
Before
Section titled “Before”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") }); },});Migration checklist
Section titled “Migration checklist”- Remove
emitfrom thecommandsparameter list. - Keep commands limited to actor/store/observable intent.
- Add
effects(snapshot, prevSnapshot, ctx). - Compare
snapshotwithprevSnapshotbefore emitting. - Keep your
eventsmap soemitstays typed.
Scripted assist
Section titled “Scripted assist”From the repo root:
node scripts/migrate-emit-to-effects.mjsThe script reports files that still:
- destructure
emitincommands - call
emit(...)in code that likely needs migration
Use --report <path> to save the output to a file.
Breaking release note
Section titled “Breaking release note”emit has been removed from command context. Commands still receive { actor, command, host }; typed event emission belongs in effects().
Release boundary
Section titled “Release boundary”- Migration tooling and docs remain available to help with old command emit patterns.
effects()is now the supported path for typed event emission.