FSM, Games and UI
development
...Once upon a time a front-end engineer
Name
Initial
Editing
Name
Saving
Name
Name
Name
Initial
Name
Click
Initial
Name
Editing
Click
Name
Saving
Name
Initial
...once upon a time a designer
“I forgot a detail, we didn’t treat
the error state”
...once upon a time a designer
“when with errors, the input
should back to editing state. so
the client can try save again”
...Our buddy front-end saw that the solution
wasn’t good enough
1 boolean = True False
isEditing + isSaving + isError
1 2 3 4
5 6 7 8
… so he had a better idea
Keep the state using boolean variables is confuse.
requiring extra treatments of all possible states and
pray to any other edge case never appears
Problem
Have a single state at a time and
define transitions between states
using an event.
Solution
...
FINITE STATE MACHINE
A finite state machine is a mathematical model used to
represent computer programs or logic circuits. The concept is
conceived as an abstract machine that must be in one of a
finite number of states.
https://pt.wikipedia.org/wiki/M%C3%A1quina_de_estados_finita
Estado Atual →
Eventos ↓
Estado A Estado B Estado C
Evento X ... ... ...
Evento Y ... Estado C ...
Evento Z ... ... ...
Table of state transitions
StateCharts
stateChartsActions
Guards
Paralel states
Compound states
Delayed transitions Activity
https://statecharts.github.io/
...and more!
Xstate
https://xstate.js.org/docs/
StateCharts - actions/Activity
https://xstate.js.org/viz/?gist=c6ef8d8e40f74e0bfec9d9683961cf72
StateCharts - Guards
https://xstate.js.org/viz/?gist=35ed12320eb7abf9d3e0f51dfcd24cc0
Memory PG
https://xstate.js.org/viz/?gist=3ffa88ac1c45d1fa45231b428ad847a6
But, how about your web
front-end?
Checkout form / lib
https://xstate.js.org/viz/?gist=bf4a9749bd45bf08313d13945c6597a9
Graphql devtools
https://xstate.js.org/viz/?gist=8637e64f733e467668de542eb86195bc
code is for humans
YOu don’t need any
library to use state
charts.
but...
Xstate
https://xstate.js.org/docs/
Xstate/FSM
https://xstate.js.org/docs/packages/xstate-fsm/
robot
https://thisrobot.life/
what else?
WRITE LESS TESTS
WITH MODEL-BASED
TESTING
define assertsadd a machine add a model choose a path
CREDITS: This presentation template was created by
Slidesgo, including icons by Flaticon, and infographics
& images by Freepik.
Thanks!
questions?
magdiel.kesller@gmail.com
https://github.com/dielduarte
https://twitter.com/diel_duarte
https://www.linkedin.com/in/dielduarte/
Please keep this slide for attribution.

Fsm, games and ui development