Created
September 18, 2019 23:32
-
-
Save mcspud/a6f0b97c392f7f661e9aafc782c99a2e to your computer and use it in GitHub Desktop.
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 otp_satisfied = (context, event) => { | |
console.log('otp_satisfied: ', context, event) | |
return true | |
} | |
const determine_challenge_type = (context, event) => { | |
console.log('determine_challenge_type', context, event) | |
return 'hello' | |
} | |
const emails_match = (context, event) => true | |
const log_result = (context, event) => console.log(context, event) | |
const raise_callback_promise = (context, event) => console.log(context, event) | |
const fire_mq_series = (context, event) => console.log(context, event) | |
const config = { | |
id: 'Update_Email', | |
initial: 'view_email', | |
context: { | |
elapsed: 0, | |
entry: 'east' | |
}, | |
states: { | |
view_email: { | |
on: { | |
NEXT: { | |
target: 'email_challenge', | |
cond: (context, event) => { | |
console.log('COND', context, event) | |
return true | |
} | |
} | |
} | |
}, | |
determine_challenge: { | |
invoke: { | |
src: async () => { | |
await true | |
console.log('done') | |
return Promise.resolve('shiieet') | |
}, | |
onDone: { | |
target: 'email_challenge' | |
}, | |
onError: { | |
target: 'error', | |
actions: (a, b) => console.log('error', a, b) | |
} | |
}, | |
}, | |
email_challenge: { | |
on: { | |
BACK: { | |
target: 'view_email', | |
}, | |
NEXT: { | |
target: 'enter_new_email', | |
cond: 'otp_satisfied' | |
} | |
}, | |
}, | |
error: { | |
type: 'final' | |
}, | |
enter_new_email: { | |
on: { | |
BACK: { | |
target: 'view_email', | |
}, | |
NEXT: { | |
target: 'confirm_new_email' | |
} | |
} | |
}, | |
confirm_new_email: { | |
on: { | |
BACK: { | |
target: 'enter_new_email', | |
}, | |
NEXT: { | |
target: 'update_email_complete', | |
cond: 'emails_match' | |
} | |
}, | |
guards: { | |
emails_match, | |
} | |
}, | |
update_email_complete: { | |
type: 'final', | |
onDone: { | |
actions: [ | |
'log_result', | |
'raise_callback_promise', | |
'fire_mq_series', | |
] | |
}, | |
}, | |
} | |
}; | |
const sideEffects = { | |
actions: { | |
log_result, | |
raise_callback_promise, | |
fire_mq_series, | |
determine_challenge_type, | |
}, | |
guards: { | |
otp_satisfied, | |
emails_match, | |
}, | |
} | |
Machine(config, sideEffects) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment