Last active
June 2, 2021 05:49
-
-
Save msell/d9fdece56e7328a52e9236a5fa7640b2 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
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
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions | |
// - XState (all XState exports) | |
const userVoted = assign({ | |
votes: (context, event) => context.votes + 1 | |
}); | |
const gatMachine = Machine({ | |
id: 'gag', | |
initial: 'idle', | |
context: { | |
votes: 0 | |
}, | |
states: { | |
idle: { | |
on: { | |
JOIN_SESSION: 'joining_session', | |
START_SESSION: 'creating_session', | |
} | |
}, | |
creating_session: { | |
initial: 'idle', | |
on: { | |
SUBMIT: '.submitting', | |
CANCEL: 'idle', | |
}, | |
states: { | |
submitting: { | |
on: { | |
SUCCESS: '#voting', | |
ERROR: 'error' | |
} | |
}, | |
idle: {}, | |
error: { | |
on: { | |
DISMISS: 'idle' | |
} | |
} | |
} | |
}, | |
joining_session: { | |
initial: 'idle', | |
on: { | |
CANCEL: 'idle', | |
SESSION_FOUND: 'voting', | |
SESSION_NOT_FOUND: '.notFound', | |
ERROR: { | |
target: '.error' | |
}, | |
}, | |
states: { | |
idle: {}, | |
error: { | |
on: { | |
DISMISS: 'idle' | |
} | |
}, | |
notFound: {} | |
} | |
}, | |
voting: { | |
id: 'voting', | |
initial: 'active', | |
on: { | |
USER_VOTED: { | |
actions: 'userVoted' | |
}, | |
END_SESSION: 'results' | |
}, | |
states: { | |
active: { | |
on: { | |
CLOCK_STARTED: 'countingDown', | |
} | |
}, | |
countingDown: { | |
} | |
} | |
}, | |
results:{ | |
on: { | |
RESET: 'idle' | |
} | |
} | |
} | |
}, { | |
actions: { userVoted } | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment