Skip to content

Instantly share code, notes, and snippets.

@selbekk
Created July 23, 2018 21:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save selbekk/8333c46a6c8f3b596c6376c17101b5b2 to your computer and use it in GitHub Desktop.
Save selbekk/8333c46a6c8f3b596c6376c17101b5b2 to your computer and use it in GitHub Desktop.
API state machine part 1
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