Skip to content

Instantly share code, notes, and snippets.

@rjdestigter
Last active March 6, 2020 18:27
Show Gist options
  • Save rjdestigter/5913857f07f66c52ffb3dac653a86115 to your computer and use it in GitHub Desktop.
Save rjdestigter/5913857f07f66c52ffb3dac653a86115 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
const promiseState = id => ({
initial: "inProgress",
states: {
inProgress: {
on: {
REJECT: "#promiseAll.rejected",
['RESOLVE' + id]: {
target: "done"
}
}
},
done: {
type: "final",
entry: send('RESOLVE')
}
}
});
const promiseAll = Machine({
id: "promiseAll",
initial: "idle",
context: {},
states: {
idle: {
on: {
RUN: "progress"
}
},
progress: {
type: "parallel",
states: {
promise1: promiseState(1),
promise2: promiseState(2),
promise3: promiseState(3),
resolver: {
initial: "0",
states: {
0: {
on: {
RESOLVE: "1"
}
},
1: {
on: {
RESOLVE: "2"
}
},
2: {
on: {
RESOLVE: "done"
}
},
done: {
on: {
"": "#promiseAll.resolved"
},
type: "final"
}
}
}
}
},
resolved: {
type: "final"
},
rejected: {
type: "final"
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment