Skip to content

Instantly share code, notes, and snippets.

@dsadhanala
Created May 2, 2020 19:26
Show Gist options
  • Save dsadhanala/45edf72978584829480cd021fe09e137 to your computer and use it in GitHub Desktop.
Save dsadhanala/45edf72978584829480cd021fe09e137 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const childMachine = Machine({
id: "child",
initial: "step1",
states: {
step1: {
entry: ['logState'],
on: { STEP: "step2" }
},
step2: {
entry: ['logState'],
on: { STEP: "step3" }
},
step3: {
entry: ['logState'],
type: "final"
}
}
},
{
actions: {
logState: (_, event, meta) => console.info(event, meta.state.value)
}
});
const parentMachine = Machine({
id: "parent",
initial: "idle",
states: {
idle: {
on: { ACTIVATE: "active" }
},
active: {
invoke: {
id: 'child',
src: childMachine,
onDone: 'done'
},
on: {
STEP: {
actions: send("STEP", {
to: "child"
})
}
}
},
done: {}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment