Skip to content

Instantly share code, notes, and snippets.

@trickydisco78
Last active April 30, 2020 13:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trickydisco78/63b72e43fa28028abfde3401be421527 to your computer and use it in GitHub Desktop.
Save trickydisco78/63b72e43fa28028abfde3401be421527 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 isNoOrImproveRoute = (context, event) => {
return context.initialFeedback === "no" || "improve";
};
feedbackMachine = Machine({
id: "feedback-machine",
initial: "idle",
context: {
initialFeedback: "no"
},
states: {
idle: {
on: {
SUBMIT: [
{target: "submitting",
actions: assign({ initialFeedback: (_ctx, e) => e.value })
}
]
}
},
submitting: {
invoke: {
id: "submitinitial",
// src: (context, event) => fetchUser(context.userId),
onDone: [
{
target: "initialsuccess",
actions: assign({ initialFeedback: (context, event) => event.data }),
cond: !isNoOrImproveRoute
},
{
target: "formpanelopened",
actions: assign({ initialFeedback: (context, event) => event.data }),
cond: isNoOrImproveRoute
}
],
onError: {
target: "initialerror",
actions: assign({ error: (context, event) => event.data })
}
}
},
initialerror: {},
initialsuccess: {},
formpanelopened: {},
formpanelerror: {},
opened: {
on: {
CLOSE: "closed",
CLICK: {
actions: assign({ rating: (ctx, e) => e.value })
}
}
},
closed: {
on: {
CLICK_BUTTON: "opened"
}
}
}},
{
guards: {
isNoOrImproveRoute // optional, if the implementation doesn't change
}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment