Last active
April 11, 2020 01:11
-
-
Save cellog/081c4c91124ea3d4128af8eeb3530ac2 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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