Created
June 19, 2021 19:55
-
-
Save BrunoQuaresma/596dced3ad6596fdd906e3dbcd0b2f73 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or 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 searchMachine = Machine({ | |
id: "seach", | |
initial: "idle", | |
context: { | |
results: undefined, | |
query: undefined, | |
lastSearchedQuery: undefined | |
}, | |
states: { | |
idle: { | |
on: { | |
SEARCH: { | |
target: "searching", | |
actions: assign({ | |
query: (ctx, event) => event.query, | |
}), | |
}, | |
}, | |
}, | |
searching: { | |
invoke: { | |
id: "fetchSearch", | |
src: () => {}, | |
onDone: { | |
target: "completed", | |
actions: assign({ | |
results: (ctx, event) => event.data, | |
lastSearchedQuery: (ctx) => ctx.query, | |
}), | |
}, | |
onError: "failed", | |
}, | |
}, | |
completed: {}, | |
failed: {}, | |
}, | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment