Skip to content

Instantly share code, notes, and snippets.

@cellog
Last active April 11, 2020 01:12
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 cellog/b582c277f54867d144c6795cd6000aa7 to your computer and use it in GitHub Desktop.
Save cellog/b582c277f54867d144c6795cd6000aa7 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 commonActions = {
SEARCH: [{
target: "error",
cond: (_, { name }) => !name,
actions: assign({
errorMessage: "The name cannot be empty."
})
}, {
target: "search",
actions: assign((_, {
name, type, projectId, datasetId
}) => ({
errorMessage: "",
name, type, projectId, datasetId,
}))
}]
}
const nameFilterMachine = Machine({
id: 'name filter',
initial: 'idle',
context: {
errorMessage: "",
name: "",
type: "",
datasetId: "",
projectId: "",
},
states: {
idle: {
on: {
...commonActions,
}
},
error: {
on: {
...commonActions,
}
},
search: {
type: "final",
}
},
onDone: {
actions: "sendSearch",
}
}, {
actions: {
sendSearch: send(({ name, type, projectId, datasetId }) => ({
type: "SEARCH",
url: `/projects/${projectId}/${type}/filter-by-name?dataset_id=${datasetId}&name=${name}`,
body: undefined,
}), {
to: "data object paging"
})
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment