Skip to content

Instantly share code, notes, and snippets.

@signaes
Created January 25, 2023 17:34
Show Gist options
  • Save signaes/2c1016abe4398e3350e8ba38b92e2b0f to your computer and use it in GitHub Desktop.
Save signaes/2c1016abe4398e3350e8ba38b92e2b0f 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: 'share-location',
initial: 'idle',
context: {
retries: 0
},
states: {
idle: {
on: {
FETCH: 'loading'
}
},
loading: {
on: {
RESOLVE: 'success',
REJECT: 'failure'
}
},
success: {
initial: 'idle',
states: {
idle: {
on: {
SHARE_LOCATION: 'sharingLocation',
CREATE_GROUP: 'creatingGroup',
UPDATE_GROUP: 'updatingGroup',
DELETE_GROUP: 'deletingGroup',
},
},
sharingLocation: {
initial: 'idle',
on: {
CANCEL: 'idle',
},
states: {
idle: {
on: {
CHOSE_GROUP_TO_SHARE: 'choseGroupToShare',
}
},
choseGroupToShare: {
initial: 'idle',
on: {
CANCEL: 'idle',
},
states: {
idle: {
on: {
CHOSEN: 'share'
}
},
share: {
on: {
CANCEL: 'idle',
COMPLETE: '#share-location.success.idle'
}
}
}
},
}
},
creatingGroup: {
on: {
CANCEL: 'idle',
COMPLETE: 'idle'
}
},
updatingGroup: {
on: {
CANCEL: 'idle',
COMPLETE: 'idle'
}
},
deletingGroup: {
on: {
CANCEL: 'idle',
COMPLETE: 'idle'
}
}
}
},
failure: {
on: {
RETRY: {
target: 'loading',
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