Skip to content

Instantly share code, notes, and snippets.

@boogie666
Last active May 15, 2019 10:06
Show Gist options
  • Save boogie666/422026f5ee66d64ccc0f3532f27fb3c0 to your computer and use it in GitHub Desktop.
Save boogie666/422026f5ee66d64ccc0f3532f27fb3c0 to your computer and use it in GitHub Desktop.
fsm state runner 'api'
function checkLogin(state){
if(state.data.username == "admin"){
return {
...state,
transitionTo: "valid"
};
}else {
return {
...state,
transitionTo: "invalid"
};
}
}
function showLogin(state){
return {
data : {
...state.data,
message: "Logged in as " + state.data.username,
},
transitionTo: "done"
};
}
function showError(state){
return {
data : {
...state.data,
message: "Username " + state.data.username + " is invalid"
},
transitionTo: "done"
};
}
let fsmRunner = {
"checkLogin": checkLogin,
"showLogin" : showLogin,
"showError" : showError
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment