Last active
February 9, 2020 06:03
-
-
Save devstojko/4e39d82fb96eece652f720319c4f6210 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 states = { | |
IDLE: 'IDLE', | |
LOADING: 'LOADING', | |
READY: 'READY', | |
ERROR: 'ERROR' | |
} | |
const events = { | |
SELECT: 'SELECT', | |
SUBMIT: 'SUBMIT', | |
} | |
const resultsMachine = Machine({ | |
id: 'resultsMachine', | |
initial: [states.IDLE], | |
context: { | |
origin: null, | |
destination: null, | |
}, | |
states: { | |
[states.IDLE]: { | |
on: { | |
[events.SELECT]: { | |
actions: assign((ctx, e) => ({ | |
...ctx, | |
[e.payload.property]: e.payload.data | |
})) | |
}, | |
[events.SUBMIT]: { | |
cond: (ctx, e) => ctx.origin && ctx.destination, | |
target: states.LOADING, | |
} | |
} | |
}, | |
[states.LOADING]: { | |
invoke: { | |
} | |
}, | |
[states.READY]: { | |
}, | |
[states.ERROR]: { | |
} | |
} | |
}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment