Last active
August 7, 2021 11:54
-
-
Save mwangaben/fe978e80a56fab40ddfe41d75fc95e79 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 createUser = function() { | |
alert('Makng User'); | |
} | |
const fetchMachine = Machine({ | |
id: 'register', | |
initial: 'idle', | |
context: { | |
form: { | |
name: '', | |
email: '', | |
password: '' | |
}, | |
users: [], | |
error: '', | |
retries: 0 | |
}, | |
states: { | |
idle: { | |
on: { | |
SUBMIT: 'submitting' | |
}, | |
}, | |
submitting: { | |
// actions: ['registerUser'], | |
invoke: { | |
id: 'saveUser', | |
src: (context, event) => createUser(), | |
onDone:{ | |
target: 'success', | |
actions: assign({ users: (context, event) => context.users.push(event.data) }) | |
}, | |
onError: { | |
target: 'failure', | |
actions: assign({ error: (context, event) => event.data }) | |
} | |
} | |
// on: { | |
// RESOLVE: 'success', | |
// REJECT: 'failure' | |
// } | |
}, | |
success: { | |
on:{ | |
SUCCESS:'inform' | |
} | |
}, | |
inform:{ | |
on: { | |
OK: 'idle' | |
} | |
}, | |
failure: { | |
on: { | |
RETRY: { | |
target: 'idle', | |
actions: assign({ | |
retries: (context, event) => context.retries + 1 | |
}) | |
} | |
} | |
}, | |
actions: { | |
// registerUser | |
} | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment