Skip to content

Instantly share code, notes, and snippets.

@cdaringe
Last active October 26, 2022 00:09
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 cdaringe/7eeee19aca0afbdc1ec11011d962eeb1 to your computer and use it in GitHub Desktop.
Save cdaringe/7eeee19aca0afbdc1ec11011d962eeb1 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: 'fetch',
initial: 'idle',
context: {
retries: 0
},
states: {
idle: {
on: {
EVT_UPDATE_NOTIFICATION: 'get_notification_from_db'
}
},
get_notification_from_db: {
on: {
OK_SOME_DB_RECORD: 'ok_some_db_record',
OK_NONE_DB_RECORD: 'weak_success',
ERROR_DB_RECORD: 'db_failure'
}
},
weak_success: {
type: 'final'
},
success: {
type: 'final'
},
ok_some_db_record: {
on: {
"UNSEEN_TO_READ": "update_record",
"UNREAD_TO_READ": "update_record",
"UNSEEN_TO_UNREAD": "update_record",
"OTHER": "invalid_update_msg"
}
},
update_record: {
on: {
OK_DB_WRITE: 'success',
ERROR_DB_WRITE: 'db_failure'
}
},
invalid_update_msg: {
type: "final"
},
db_failure: {
on: {
RETRY: {
target: 'get_notification_from_db',
actions: assign({
retries: (context, event) => context.retries + 1
})
}
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment