Skip to content

Instantly share code, notes, and snippets.

@parties
Last active November 15, 2019 18:26
Show Gist options
  • Save parties/87c88987f5c4486dea99e7a31271068a to your computer and use it in GitHub Desktop.
Save parties/87c88987f5c4486dea99e7a31271068a to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// https://xstate.js.org/viz/?gist=87c88987f5c4486dea99e7a31271068a
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
const customerSearchMachine = Machine({
id: "customer-search",
initial: "idle",
context: {
searchQuery: "",
searchType: "phoneNumber",
transactionId: "0",
customer: null,
},
states: {
idle: {
on: {
UPDATE_CUSTOMER_SEARCH_QUERY: {
target: "idle",
actions: "updateQuery",
},
SET_CUSTOMER_SEARCH_TYPE: {
target: "idle",
actions: "setQueryType",
},
CLEAR_QUERY: {
target: "idle",
actions: "clearQuery",
},
SUBMIT: [
{
target: "searching",
cond: "isValidQuery",
},
{ target: "error" },
],
}
},
searching: {
on: {
RESOLVE: "success",
REJECT: "error"
}
},
success: {
type: "final"
},
error: {
on: {
CLEAR_QUERY: {
target: "idle",
actions: "clearQuery",
},
UPDATE_CUSTOMER_SEARCH_QUERY: {
target: "idle",
actions: "updateQuery",
},
SET_CUSTOMER_SEARCH_TYPE: {
target: "idle",
actions: "setQueryType",
},
}
}
}
}, {
guards: {
isValidQuery: () => true
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment