Skip to content

Instantly share code, notes, and snippets.

@wlee221
Last active June 30, 2021 09:28
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 wlee221/90fce99ca481f96b238c023791d95c4c to your computer and use it in GitHub Desktop.
Save wlee221/90fce99ca481f96b238c023791d95c4c to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const fetchMachine = Machine({
id: "signUp",
initial: "edit",
type: 'parallel',
states: {
validation: {
initial: 'pending',
states: {
pending: {
invoke: {
src: "validate",
onDone: "valid",
onError: {
target: "invalid",
actions: "setFieldErrors"
}
}
},
valid: {},
invalid: {}
},
on: {
CHANGE: {
target: ".pending"
},
BLUR: {
target: ".pending"
}
}
},
submission: {
initial: "idle",
onDone: {
target: "."
},
states: {
idle: {
on: {
SUBMIT: {
target: 'pending',
// cond: "isValid"
}
}
},
pending: {
invoke: {
src: "signUp",
onDone: "done",
onError: {
target: "error",
actions: "setFieldError"
}
}
},
error: {
on: {
SUBMIT: {
target: "pending",
// cond: "isValid"
}
}
},
done: {
type: "final"
}
},
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment