Skip to content

Instantly share code, notes, and snippets.

@cellog
Last active April 11, 2020 01:11
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/081c4c91124ea3d4128af8eeb3530ac2 to your computer and use it in GitHub Desktop.
Save cellog/081c4c91124ea3d4128af8eeb3530ac2 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_CITRINE_ID: [{
target: "error",
cond: "isValidUUID",
actions: assign({
errorMessage: "Invalid Citrine ID, must be a valid UUID",
})
}, {
target: "search"
}],
SEARCH_CUSTOM_UID: {
target: "search",
actions: assign((_, { uid, scope, datasetId, projectId }) => ({
errorMessage: "", uid, scope, datasetId, projectId
})),
}
}
const uidFilterMachine = Machine({
id: 'uid filter',
initial: 'idle',
context: {
scope: "id",
uid: "",
errorMessage: "",
datasetId: "",
projectId: "",
},
states: {
idle: {
on: {
...commonActions,
}
},
error: {
on: {
...commonActions,
}
},
search: {
type: "final",
},
},
onDone: {
actions: "sendSearch"
}
}, {
actions: {
sendSearch: send(({ scope, uid, projectId, datasetId }) => ({
type: "SEARCH",
url: `/projects/${projectId}/datasets/${datasetId}/storables/${scope}/${uid}`,
body: undefined,
}), {
to: "data object paging"
})
},
guards: {
isValidUUID: (_, { uid }) => {
// TODO: check regex
return Math.random() < 0.5
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment