Created
April 16, 2020 01:12
-
-
Save NullVoxPopuli/76aa67eadc0d8536e1f4fdce223e5748 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or 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 parseScannedData = assign((context, event) => { | |
let { json } = event; | |
let isValid = Array.isArray(json); | |
if (!isValid) { | |
raise('SCAN_ERROR'); | |
return context; | |
} | |
return json; | |
}); | |
const foo = Machine({ | |
id: 'scan-qr-code', | |
strict: true, | |
initial: 'idle', | |
context: { | |
intent: undefined, | |
data: undefined, | |
}, | |
states: { | |
idle: { | |
on: { | |
SCAN: { | |
target: 'scanned', | |
}, | |
}, | |
}, | |
scanned: { | |
invoke: { | |
id: 'parse', | |
src: parseScannedData, | |
onError: { | |
target: 'scanError', | |
}, | |
onDone: { | |
target: 'loginRequest', | |
actions: (context, event) => { | |
return { | |
...context, | |
intent: event.data[0], | |
data: event.data[1], | |
}; | |
}, | |
}, | |
}, | |
on: { | |
SCAN_ERROR: {}, | |
}, | |
}, | |
scanError: { | |
entry: () => console.log('entered scanError'), | |
}, | |
loginRequest: { | |
entry: () => console.log('entered login request'), | |
}, | |
addFriend: {}, | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment