Created
July 23, 2018 21:10
-
-
Save selbekk/8333c46a6c8f3b596c6376c17101b5b2 to your computer and use it in GitHub Desktop.
API state machine part 1
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
class ApiStateMachine { | |
state = { | |
current: 'idle', | |
}; | |
next(input) { | |
let nextState; | |
switch (this.state.current) { | |
case 'idle': nextState = 'pending'; break; | |
case 'pending': nextState = input ? 'success' : 'error'; break; | |
default: nextState = 'idle'; | |
} | |
this.state.current = nextState; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment