Last active
August 30, 2021 06:08
-
-
Save karlguillotte/92f2679c9fcbd3212671645102b02351 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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