Last active
May 15, 2019 10:06
-
-
Save boogie666/422026f5ee66d64ccc0f3532f27fb3c0 to your computer and use it in GitHub Desktop.
fsm state runner 'api'
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
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