Skip to content

Instantly share code, notes, and snippets.

@hnordt
Created July 29, 2019 22:53
Show Gist options
  • Save hnordt/557c30812c13175c545fbb6c99d15f57 to your computer and use it in GitHub Desktop.
Save hnordt/557c30812c13175c545fbb6c99d15f57 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
const fetchMachine = Machine({
"id": "form",
"context": {
"initialValues": {},
"values": {},
"errors": null
},
"type": "parallel",
"states": {
"condition": {
"initial": "pristine",
"states": {
"pristine": {
"onEntry": "resetValues",
"on": {
"CHANGE": "dirty1"
}
},
"dirty1": {
"onEntry": ["setValue", "resetError"],
"invoke": {
"src": "validate",
"onDone": {
"actions": "resetErrors"
},
"onError": {
"actions": "setErrors"
}
},
"on": {
"CHANGE": "dirty2",
"RESET": "pristine"
}
},
"dirty2": {
"onEntry": ["setValue", "resetError"],
"invoke": {
"src": "validate",
"onDone": {
"actions": "resetErrors"
},
"onError": {
"actions": "setErrors"
}
},
"on": {
"CHANGE": "dirty1",
"RESET": "pristine"
}
}
}
},
"submission": {
"initial": "idle",
"states": {
"idle": {
"on": {
"SUBMIT": "submitted"
}
},
"submitted": {
"initial": "pending",
"states": {
"pending": {
"invoke": {
"src": "validate",
"onDone": "success",
"onError": "failure"
}
},
"success": {
"onEntry": "notifySuccess"
},
"failure": {
"onEntry": "setErrors",
"onExit": "resetErrors"
}
},
"on": {
"SUBMIT": ".pending",
"RESET": "idle"
}
}
}
}
}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment