Skip to content

Instantly share code, notes, and snippets.

@karlguillotte
Last active August 30, 2021 06:08
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 karlguillotte/92f2679c9fcbd3212671645102b02351 to your computer and use it in GitHub Desktop.
Save karlguillotte/92f2679c9fcbd3212671645102b02351 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const appStateMachine = Machine({
id: 'app-state',
initial: 'setup',
states: {
setup: {
invoke: {
id: 'listen',
src: 'setup'
},
},
active: {},
inactive: {},
},
on: {
ACTIVE: 'active',
INACTIVE: 'inactive',
}
}, {
services: {
setup: () => callback => {
const listener = AppState.addEventListener('change', nextState => {
if (nextState === 'active') {
callback('ACTIVE')
} else {
callback('INACTIVE')
}
})
return () => {
listener.remove()
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment