SlideShare a Scribd company logo
Are statecharts the next
big UI paradigm?
Luca Matteis
github.com/lmatteis
@lmatteis
Hootsuite office in Rome, Italy
Designers build images of
each possible state of our UI.
When we convert these images
(or states) into code we lose the
high-level understanding of our
app.
var isLoggedIn, isInProgress, isSuccessful;
// display the form
isLoggedIn = false;
isInProgress = false;
isSuccessful = false;
// request in flight
isLoggedIn = false;
isInProgress = true;
isSuccessful = false;
// display a successful message
isLoggedIn = true;
isInProgress = false;
isSuccessful = true;
// display welcome message + links
isLoggedIn = true;
isInProgress = false;
isSuccessful = false;
var isRequestFinished, isInProgress, isSuccessful, isFailed;
if (isInProgress) {
// request in flight, render a spinner
} else if (isRequestFinished) {
if (isSuccessful) {
// request successful, render a message
} else if (isFailed) {
// render error message + try again link
} else {
// render welcome message + links
}
} else {
// waiting for input, render login form
}
As our app grows,
understanding which section is
responsible for each state
becomes increasingly difficult.
Not all questions can be
answered using a set of
images.
• What if the user clicks the submit button repeatedly? 😛
• What if the user wants to cancel the submit while it's in-flight? ✈
• What if the user mischievously enables the disabled button? 😕
• Is there any indication that the request is fetching? 🙄
• What happens if there's an error? Can the user resubmit the form? ❓
• What if the user submits and then clicks a different page? What should
happen? 🤷
It seems we don’t have a
technological problem. We
have a thinking problem.
How do we set ourselves to
answer these questions, and be
able to have both our design
and our code depend on the
answers?
Statecharts
Awake
Day simulator
Dressed
Fed
Ready
Work
Cafe
Home
Asleep
Alarm
Dress
Eat
Eat
Dress
GoToWork
Think
Yawn
Coffee
GoHome
Read WatchTv
Empty form
Submitting
SUBMIT
RESOLVE
REJECT
Welcome
page
Error page
REGISTER
REGISTER
LOGOUT
Login page
REGISTER
Statecharts have 3
important concepts:
1) Hierarchical (nested) states 🌳
2) History states (
3) Parallel states ⏰
Empty form
Submitting
SUBMIT
RESOLVE
REJECT
Welcome
page
Error page
REGISTER
REGISTER
LOGOUT
Login page
REGISTER
Empty form
Submitting
SUBMIT
RESOLVEREJECT
Welcome
page
Error page
REGISTER
LOGOUT
Login page
Hierarchical (nested) states 🌳
Unclustering Welcome page
Login page
GetTickets
TicketsRESOLVE
REFRESH
Empty form
Submitting
SUBMIT
History states
Welcome page
GetTickets
TicketsRESOLVE
REFRESH
H
Parallel states
Welcome page
GetTickets
TicketsRESOLVE
REFRESH
Sidebar
Init
Loading
SEARCH
RESOLVE
Items
These representations can
drive both our design and
our code.
• What if the user clicks the submit button repeatedly? 😛
• What if the user wants to cancel the submit while it's in-flight? ✈
• What if the user mischievously enables the disabled button? 😕
• Is there any indication that the request is fetching? 🙄
• What happens if there's an error? Can the user resubmit the form? ❓
• What if the user submits and then clicks a different page? What should happen? 🤷
Empty form
Submitting
SUBMIT
• What if the user clicks the submit button repeatedly? 😛
• What if the user wants to cancel the submit while it's in-flight? ✈
• What if the user mischievously enables the disabled button? 😕
• Is there any indication that the request is fetching? 🙄
• What happens if there's an error? Can the user resubmit the form? ❓
• What if the user submits and then clicks a different page? What should happen? 🤷
Empty form
Submitting
SUBMIT
SUBMIT
• What if the user clicks the submit button repeatedly? 😛
• What if the user wants to cancel the submit while it's in-flight? ✈
• What if the user mischievously enables the disabled button? 😕
• Is there any indication that the request is fetching? 🙄
• What happens if there's an error? Can the user resubmit the form? ❓
• What if the user submits and then clicks a different page? What should happen? 🤷
Empty form
Submitting
SUBMIT
SUBMIT
CANCEL
• What if the user clicks the submit button repeatedly? 😛
• What if the user wants to cancel the submit while it's in-flight? ✈
• What if the user mischievously enables the disabled button? 😕
• Is there any indication that the request is fetching? 🙄
• What happens if there's an error? Can the user resubmit the form? ❓
• What if the user submits and then clicks a different page? What should happen? 🤷
Empty form
Submitting
SUBMIT
SUBMIT
CANCEL
Error
REJECT
Such diagram can be
described using JSON and
our UI code can directly be
driven by its description.
https://github.com/davidkpiano/xstate
What about setState() and
Redux?
The term state used within
the statechart formalism
simply describes a textual
label which drives our
program in understanding
what needs to happen.
To the contrary, in the
React world the term state
usually describes some
data that we use to render
our components.
Statecharts actually merry
quite well with a system
like Redux.
Redux and Statecharts
const initialState = {
isRequestFinished: false,
isInProgress: false,
isSuccessful: false,
isFailed: false
};
function reducer(state = initialState, action) {
…
}
render() {
if (isInProgress) {
// request in flight, render a spinner
} else if (isRequestFinished) {
if (isSuccessful) {
// request successful, render a message
} else if (isFailed) {
// render error message + try again link
} else {
// render welcome message + links
}
} else {
// waiting for input, render login form
}
}
Redux and Statecharts
const initialState = null;	
function reducer(state = initialState, action) {	
return machine	
.transition(state, action.type)	
.value;	
}
machine = Machine({
initial: 'init',
states: {
init: {
on: {
SUBMIT: ‘submitting’,
},
},
submitting: {
on: {
RESOLVE: ‘success’,
REJECT: ‘error’
}
},
error: {
on: {
TRY_AGAIN: ‘init’,
}
}
}
});
render() {
if (isInProgress) {
// request in flight, render a spinner
} else if (isRequestFinished) {
if (isSuccessful) {
// request successful, render a message
} else if (isFailed) {
// render error message + try again link
} else {
// render welcome message + links
}
} else {
// waiting for input, render login form
}
}
Redux and Statecharts
const initialState = null;	
function reducer(state = initialState, action) {	
return machine	
.transition(state, action.type)	
.value;	
}
machine = Machine({
initial: 'init',
states: {
init: {
on: {
SUBMIT: ‘submitting’,
},
},
submitting: {
on: {
RESOLVE: ‘success’,
REJECT: ‘error’
}
},
error: {
on: {
TRY_AGAIN: ‘init’,
}
}
}
});
render() {
const renderMap = {
[submitting]: // request in flight, render a spinner
[success]: // request successful, render a message
[error]: // render error message + try again link
[init]: // waiting for input, render login form
}
return renderMap[this.props.state];
}
Redux and Statecharts
const initialState = null;	
function reducer(state = initialState, action) {	
return machine	
.transition(state, action.type)	
.value;	
}
machine = Machine({
initial: 'init',
states: {
init: {
on: {
SUBMIT: ‘submitting’,
},
},
submitting: {
on: {
RESOLVE: ‘success’,
REJECT: ‘error’
}
},
error: {
on: {
TRY_AGAIN: ‘init’,
}
}
}
});
store.dispatch({ type: SUBMIT });
store.dispatch({ type: RESOLVE });
store.dispatch({ type: REJECT });
store.dispatch({ type: TRY_AGAIN });
You can continue using
other reducers for other
non-statechart data.
Redux and Statecharts
const initialState = null;	
function reducer(state = initialState, action) {	
return machine	
.transition(state, action.type)	
.value;	
}
store.dispatch({ type: SUBMIT });
store.dispatch({ type: RESOLVE, payload });
store.dispatch({ type: REJECT });
store.dispatch({ type: TRY_AGAIN });
function resolveReducer(state = null, action) {	
switch (action.type) {	
case RESOLVE:	
return action.payload;	
default:	
return state;	
}	
}
Redux and Statecharts
const initialState = null;	
function reducer(state = initialState, action) {	
return machine	
.transition(state, action.type)	
.value;	
}
store.dispatch({ type: SUBMIT });
store.dispatch({ type: RESOLVE, payload });
store.dispatch({ type: REJECT });
store.dispatch({ type: TRY_AGAIN });
function resolveReducer(state = null, action) {	
switch (action.type) {	
case RESOLVE:	
return action.payload;	
default:	
return state;	
}	
}
render() {
const renderMap = {
[submitting]: // request in flight, render a spinner
[success]: renderMessage(this.props.resolveData)
[error]: // render error message + try again link
[init]: // waiting for input, render login form
}
return renderMap[this.props.state];
}
Statecharts provide us with
a visual formalism that can
tie the functioning of our
code and our designs
together.
Whenever you find yourself
writing lots of isSomething
variables in your state,
maybe it’s time to give
statecharts a try!
Further reading:
Pure UI Control by Adam Solove https://medium.com/@asolove/
pure-ui-control-ac8d1be97a8d
STATECHARTS: A VISUAL FORMALISM FOR COMPLEX SYSTEMS
http://www.inf.ed.ac.uk/teaching/courses/seoc/2005_2006/
resources/statecharts.pdf
You are managing state? Think twice. by Krasimir Tsonev
http://krasimirtsonev.com/blog/article/managing-state-in-
javascript-with-state-machines-stent
Infinitely Better UIs with Finite Automata by David Khourshid
https://www.youtube.com/watch?v=VU1NKX6Qkxc
Rambling thoughts on React and Finite State Machines by
Ryan Florence https://www.youtube.com/watch?v=MkdV2-U16tc
Thanks!

More Related Content

What's hot

Java Serialization
Java SerializationJava Serialization
Java Serializationimypraz
 
Introduction to Hibernate
Introduction to HibernateIntroduction to Hibernate
Introduction to Hibernate
Krishnakanth Goud
 
Android Components
Android ComponentsAndroid Components
Android Components
Aatul Palandurkar
 
SQLITE Android
SQLITE AndroidSQLITE Android
SQLITE Android
Sourabh Sahu
 
Express js
Express jsExpress js
Express js
Manav Prasad
 
ASP.NET Web API
ASP.NET Web APIASP.NET Web API
ASP.NET Web APIhabib_786
 
Event In JavaScript
Event In JavaScriptEvent In JavaScript
Event In JavaScript
ShahDhruv21
 
Angular Directives
Angular DirectivesAngular Directives
Angular Directives
iFour Technolab Pvt. Ltd.
 
Layouts in android
Layouts in androidLayouts in android
Layouts in android
Durai S
 
Introduction to Redux
Introduction to ReduxIntroduction to Redux
Introduction to Redux
Ignacio Martín
 
Event handling
Event handlingEvent handling
Javascript Prototype Visualized
Javascript Prototype VisualizedJavascript Prototype Visualized
Javascript Prototype Visualized
军 沈
 
Solid principles
Solid principlesSolid principles
Solid principles
Monica Rodrigues
 
Asp.net mvc basic introduction
Asp.net mvc basic introductionAsp.net mvc basic introduction
Asp.net mvc basic introduction
Bhagath Gopinath
 
Event handling
Event handlingEvent handling
Event handling
swapnac12
 
Introducing Clean Architecture
Introducing Clean ArchitectureIntroducing Clean Architecture
Introducing Clean Architecture
Roc Boronat
 
Hexagonal architecture - message-oriented software design
Hexagonal architecture  - message-oriented software designHexagonal architecture  - message-oriented software design
Hexagonal architecture - message-oriented software design
Matthias Noback
 
Introduction to Listview in Android
Introduction to Listview in AndroidIntroduction to Listview in Android
Introduction to Listview in Android
technoguff
 

What's hot (20)

Java Serialization
Java SerializationJava Serialization
Java Serialization
 
Introduction to Hibernate
Introduction to HibernateIntroduction to Hibernate
Introduction to Hibernate
 
Android Components
Android ComponentsAndroid Components
Android Components
 
SQLITE Android
SQLITE AndroidSQLITE Android
SQLITE Android
 
Express js
Express jsExpress js
Express js
 
ASP.NET Web API
ASP.NET Web APIASP.NET Web API
ASP.NET Web API
 
Event In JavaScript
Event In JavaScriptEvent In JavaScript
Event In JavaScript
 
Angular Directives
Angular DirectivesAngular Directives
Angular Directives
 
Layouts in android
Layouts in androidLayouts in android
Layouts in android
 
Introduction to Redux
Introduction to ReduxIntroduction to Redux
Introduction to Redux
 
Event handling
Event handlingEvent handling
Event handling
 
Javascript Prototype Visualized
Javascript Prototype VisualizedJavascript Prototype Visualized
Javascript Prototype Visualized
 
Solid principles
Solid principlesSolid principles
Solid principles
 
Asp.net mvc basic introduction
Asp.net mvc basic introductionAsp.net mvc basic introduction
Asp.net mvc basic introduction
 
AngularJS
AngularJS AngularJS
AngularJS
 
Difference between association, aggregation and composition
Difference between association, aggregation and compositionDifference between association, aggregation and composition
Difference between association, aggregation and composition
 
Event handling
Event handlingEvent handling
Event handling
 
Introducing Clean Architecture
Introducing Clean ArchitectureIntroducing Clean Architecture
Introducing Clean Architecture
 
Hexagonal architecture - message-oriented software design
Hexagonal architecture  - message-oriented software designHexagonal architecture  - message-oriented software design
Hexagonal architecture - message-oriented software design
 
Introduction to Listview in Android
Introduction to Listview in AndroidIntroduction to Listview in Android
Introduction to Listview in Android
 

Similar to Are statecharts the next big UI paradigm?

A Journey with React
A Journey with ReactA Journey with React
A Journey with React
FITC
 
iOS 개발자의 Flutter 체험기
iOS 개발자의 Flutter 체험기iOS 개발자의 Flutter 체험기
iOS 개발자의 Flutter 체험기
Wanbok Choi
 
N Things You Don't Want to Repeat in React Native
N Things You Don't Want to Repeat in React NativeN Things You Don't Want to Repeat in React Native
N Things You Don't Want to Repeat in React Native
Anton Kulyk
 
Extending Redux in the Server Side
Extending Redux in the Server SideExtending Redux in the Server Side
Extending Redux in the Server Side
Ignacio Martín
 
Frontin like-a-backer
Frontin like-a-backerFrontin like-a-backer
Frontin like-a-backer
Frank de Jonge
 
How Reactive do we need to be
How Reactive do we need to beHow Reactive do we need to be
How Reactive do we need to be
Jana Karceska
 
The accidental web designer - No Code Conf 2019 Workshop
The accidental web designer - No Code Conf 2019 WorkshopThe accidental web designer - No Code Conf 2019 Workshop
The accidental web designer - No Code Conf 2019 Workshop
Webflow
 
A short tale about state machine
A short tale about state machineA short tale about state machine
A short tale about state machine
Łukasz Chruściel
 
Advanced redux
Advanced reduxAdvanced redux
Advanced redux
Boris Dinkevich
 
The biggest lies about react hooks
The biggest lies about react hooksThe biggest lies about react hooks
The biggest lies about react hooks
Marios Fakiolas
 
Roman Schejbal: From Madness To Reason
Roman Schejbal: From Madness To ReasonRoman Schejbal: From Madness To Reason
Roman Schejbal: From Madness To Reason
Develcz
 
You should be able to use the same function to check a narrowing fun.pdf
You should be able to use the same function to check a narrowing fun.pdfYou should be able to use the same function to check a narrowing fun.pdf
You should be able to use the same function to check a narrowing fun.pdf
sayandas941
 
Imagine a world without mocks
Imagine a world without mocksImagine a world without mocks
Imagine a world without mocks
kenbot
 
Serverless Functions and Vue.js
Serverless Functions and Vue.jsServerless Functions and Vue.js
Serverless Functions and Vue.js
Sarah Drasner
 
The Functional Programming Toolkit (NDC Oslo 2019)
The Functional Programming Toolkit (NDC Oslo 2019)The Functional Programming Toolkit (NDC Oslo 2019)
The Functional Programming Toolkit (NDC Oslo 2019)
Scott Wlaschin
 
Let it crash - fault tolerance in Elixir/OTP
Let it crash - fault tolerance in Elixir/OTPLet it crash - fault tolerance in Elixir/OTP
Let it crash - fault tolerance in Elixir/OTP
Maciej Kaszubowski
 
The evolution of asynchronous JavaScript
The evolution of asynchronous JavaScriptThe evolution of asynchronous JavaScript
The evolution of asynchronous JavaScript
Alessandro Cinelli (cirpo)
 
Write a C++ program which generates and displays a random walk acros.pdf
Write a C++ program which generates and displays a random walk acros.pdfWrite a C++ program which generates and displays a random walk acros.pdf
Write a C++ program which generates and displays a random walk acros.pdf
mckenziecast21211
 
Do I need tests when I have the compiler - Andrzej Jóźwiak - TomTom Dev Day 2020
Do I need tests when I have the compiler - Andrzej Jóźwiak - TomTom Dev Day 2020Do I need tests when I have the compiler - Andrzej Jóźwiak - TomTom Dev Day 2020
Do I need tests when I have the compiler - Andrzej Jóźwiak - TomTom Dev Day 2020
Andrzej Jóźwiak
 
Getting the Most Out of jQuery Widgets
Getting the Most Out of jQuery WidgetsGetting the Most Out of jQuery Widgets
Getting the Most Out of jQuery Widgets
velveeta_512
 

Similar to Are statecharts the next big UI paradigm? (20)

A Journey with React
A Journey with ReactA Journey with React
A Journey with React
 
iOS 개발자의 Flutter 체험기
iOS 개발자의 Flutter 체험기iOS 개발자의 Flutter 체험기
iOS 개발자의 Flutter 체험기
 
N Things You Don't Want to Repeat in React Native
N Things You Don't Want to Repeat in React NativeN Things You Don't Want to Repeat in React Native
N Things You Don't Want to Repeat in React Native
 
Extending Redux in the Server Side
Extending Redux in the Server SideExtending Redux in the Server Side
Extending Redux in the Server Side
 
Frontin like-a-backer
Frontin like-a-backerFrontin like-a-backer
Frontin like-a-backer
 
How Reactive do we need to be
How Reactive do we need to beHow Reactive do we need to be
How Reactive do we need to be
 
The accidental web designer - No Code Conf 2019 Workshop
The accidental web designer - No Code Conf 2019 WorkshopThe accidental web designer - No Code Conf 2019 Workshop
The accidental web designer - No Code Conf 2019 Workshop
 
A short tale about state machine
A short tale about state machineA short tale about state machine
A short tale about state machine
 
Advanced redux
Advanced reduxAdvanced redux
Advanced redux
 
The biggest lies about react hooks
The biggest lies about react hooksThe biggest lies about react hooks
The biggest lies about react hooks
 
Roman Schejbal: From Madness To Reason
Roman Schejbal: From Madness To ReasonRoman Schejbal: From Madness To Reason
Roman Schejbal: From Madness To Reason
 
You should be able to use the same function to check a narrowing fun.pdf
You should be able to use the same function to check a narrowing fun.pdfYou should be able to use the same function to check a narrowing fun.pdf
You should be able to use the same function to check a narrowing fun.pdf
 
Imagine a world without mocks
Imagine a world without mocksImagine a world without mocks
Imagine a world without mocks
 
Serverless Functions and Vue.js
Serverless Functions and Vue.jsServerless Functions and Vue.js
Serverless Functions and Vue.js
 
The Functional Programming Toolkit (NDC Oslo 2019)
The Functional Programming Toolkit (NDC Oslo 2019)The Functional Programming Toolkit (NDC Oslo 2019)
The Functional Programming Toolkit (NDC Oslo 2019)
 
Let it crash - fault tolerance in Elixir/OTP
Let it crash - fault tolerance in Elixir/OTPLet it crash - fault tolerance in Elixir/OTP
Let it crash - fault tolerance in Elixir/OTP
 
The evolution of asynchronous JavaScript
The evolution of asynchronous JavaScriptThe evolution of asynchronous JavaScript
The evolution of asynchronous JavaScript
 
Write a C++ program which generates and displays a random walk acros.pdf
Write a C++ program which generates and displays a random walk acros.pdfWrite a C++ program which generates and displays a random walk acros.pdf
Write a C++ program which generates and displays a random walk acros.pdf
 
Do I need tests when I have the compiler - Andrzej Jóźwiak - TomTom Dev Day 2020
Do I need tests when I have the compiler - Andrzej Jóźwiak - TomTom Dev Day 2020Do I need tests when I have the compiler - Andrzej Jóźwiak - TomTom Dev Day 2020
Do I need tests when I have the compiler - Andrzej Jóźwiak - TomTom Dev Day 2020
 
Getting the Most Out of jQuery Widgets
Getting the Most Out of jQuery WidgetsGetting the Most Out of jQuery Widgets
Getting the Most Out of jQuery Widgets
 

Recently uploaded

Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 

Recently uploaded (20)

Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 

Are statecharts the next big UI paradigm?

  • 1. Are statecharts the next big UI paradigm?
  • 3. Designers build images of each possible state of our UI.
  • 4.
  • 5. When we convert these images (or states) into code we lose the high-level understanding of our app.
  • 6. var isLoggedIn, isInProgress, isSuccessful; // display the form isLoggedIn = false; isInProgress = false; isSuccessful = false; // request in flight isLoggedIn = false; isInProgress = true; isSuccessful = false; // display a successful message isLoggedIn = true; isInProgress = false; isSuccessful = true; // display welcome message + links isLoggedIn = true; isInProgress = false; isSuccessful = false; var isRequestFinished, isInProgress, isSuccessful, isFailed; if (isInProgress) { // request in flight, render a spinner } else if (isRequestFinished) { if (isSuccessful) { // request successful, render a message } else if (isFailed) { // render error message + try again link } else { // render welcome message + links } } else { // waiting for input, render login form }
  • 7. As our app grows, understanding which section is responsible for each state becomes increasingly difficult.
  • 8. Not all questions can be answered using a set of images.
  • 9. • What if the user clicks the submit button repeatedly? 😛 • What if the user wants to cancel the submit while it's in-flight? ✈ • What if the user mischievously enables the disabled button? 😕 • Is there any indication that the request is fetching? 🙄 • What happens if there's an error? Can the user resubmit the form? ❓ • What if the user submits and then clicks a different page? What should happen? 🤷
  • 10. It seems we don’t have a technological problem. We have a thinking problem.
  • 11. How do we set ourselves to answer these questions, and be able to have both our design and our code depend on the answers?
  • 15. Statecharts have 3 important concepts: 1) Hierarchical (nested) states 🌳 2) History states ( 3) Parallel states ⏰
  • 18. Unclustering Welcome page Login page GetTickets TicketsRESOLVE REFRESH Empty form Submitting SUBMIT
  • 21.
  • 22. These representations can drive both our design and our code.
  • 23. • What if the user clicks the submit button repeatedly? 😛 • What if the user wants to cancel the submit while it's in-flight? ✈ • What if the user mischievously enables the disabled button? 😕 • Is there any indication that the request is fetching? 🙄 • What happens if there's an error? Can the user resubmit the form? ❓ • What if the user submits and then clicks a different page? What should happen? 🤷 Empty form Submitting SUBMIT
  • 24. • What if the user clicks the submit button repeatedly? 😛 • What if the user wants to cancel the submit while it's in-flight? ✈ • What if the user mischievously enables the disabled button? 😕 • Is there any indication that the request is fetching? 🙄 • What happens if there's an error? Can the user resubmit the form? ❓ • What if the user submits and then clicks a different page? What should happen? 🤷 Empty form Submitting SUBMIT SUBMIT
  • 25. • What if the user clicks the submit button repeatedly? 😛 • What if the user wants to cancel the submit while it's in-flight? ✈ • What if the user mischievously enables the disabled button? 😕 • Is there any indication that the request is fetching? 🙄 • What happens if there's an error? Can the user resubmit the form? ❓ • What if the user submits and then clicks a different page? What should happen? 🤷 Empty form Submitting SUBMIT SUBMIT CANCEL
  • 26. • What if the user clicks the submit button repeatedly? 😛 • What if the user wants to cancel the submit while it's in-flight? ✈ • What if the user mischievously enables the disabled button? 😕 • Is there any indication that the request is fetching? 🙄 • What happens if there's an error? Can the user resubmit the form? ❓ • What if the user submits and then clicks a different page? What should happen? 🤷 Empty form Submitting SUBMIT SUBMIT CANCEL Error REJECT
  • 27. Such diagram can be described using JSON and our UI code can directly be driven by its description.
  • 29. What about setState() and Redux?
  • 30. The term state used within the statechart formalism simply describes a textual label which drives our program in understanding what needs to happen.
  • 31. To the contrary, in the React world the term state usually describes some data that we use to render our components.
  • 32. Statecharts actually merry quite well with a system like Redux.
  • 33.
  • 34. Redux and Statecharts const initialState = { isRequestFinished: false, isInProgress: false, isSuccessful: false, isFailed: false }; function reducer(state = initialState, action) { … } render() { if (isInProgress) { // request in flight, render a spinner } else if (isRequestFinished) { if (isSuccessful) { // request successful, render a message } else if (isFailed) { // render error message + try again link } else { // render welcome message + links } } else { // waiting for input, render login form } }
  • 35. Redux and Statecharts const initialState = null; function reducer(state = initialState, action) { return machine .transition(state, action.type) .value; } machine = Machine({ initial: 'init', states: { init: { on: { SUBMIT: ‘submitting’, }, }, submitting: { on: { RESOLVE: ‘success’, REJECT: ‘error’ } }, error: { on: { TRY_AGAIN: ‘init’, } } } }); render() { if (isInProgress) { // request in flight, render a spinner } else if (isRequestFinished) { if (isSuccessful) { // request successful, render a message } else if (isFailed) { // render error message + try again link } else { // render welcome message + links } } else { // waiting for input, render login form } }
  • 36. Redux and Statecharts const initialState = null; function reducer(state = initialState, action) { return machine .transition(state, action.type) .value; } machine = Machine({ initial: 'init', states: { init: { on: { SUBMIT: ‘submitting’, }, }, submitting: { on: { RESOLVE: ‘success’, REJECT: ‘error’ } }, error: { on: { TRY_AGAIN: ‘init’, } } } }); render() { const renderMap = { [submitting]: // request in flight, render a spinner [success]: // request successful, render a message [error]: // render error message + try again link [init]: // waiting for input, render login form } return renderMap[this.props.state]; }
  • 37. Redux and Statecharts const initialState = null; function reducer(state = initialState, action) { return machine .transition(state, action.type) .value; } machine = Machine({ initial: 'init', states: { init: { on: { SUBMIT: ‘submitting’, }, }, submitting: { on: { RESOLVE: ‘success’, REJECT: ‘error’ } }, error: { on: { TRY_AGAIN: ‘init’, } } } }); store.dispatch({ type: SUBMIT }); store.dispatch({ type: RESOLVE }); store.dispatch({ type: REJECT }); store.dispatch({ type: TRY_AGAIN });
  • 38. You can continue using other reducers for other non-statechart data.
  • 39. Redux and Statecharts const initialState = null; function reducer(state = initialState, action) { return machine .transition(state, action.type) .value; } store.dispatch({ type: SUBMIT }); store.dispatch({ type: RESOLVE, payload }); store.dispatch({ type: REJECT }); store.dispatch({ type: TRY_AGAIN }); function resolveReducer(state = null, action) { switch (action.type) { case RESOLVE: return action.payload; default: return state; } }
  • 40. Redux and Statecharts const initialState = null; function reducer(state = initialState, action) { return machine .transition(state, action.type) .value; } store.dispatch({ type: SUBMIT }); store.dispatch({ type: RESOLVE, payload }); store.dispatch({ type: REJECT }); store.dispatch({ type: TRY_AGAIN }); function resolveReducer(state = null, action) { switch (action.type) { case RESOLVE: return action.payload; default: return state; } } render() { const renderMap = { [submitting]: // request in flight, render a spinner [success]: renderMessage(this.props.resolveData) [error]: // render error message + try again link [init]: // waiting for input, render login form } return renderMap[this.props.state]; }
  • 41. Statecharts provide us with a visual formalism that can tie the functioning of our code and our designs together.
  • 42.
  • 43. Whenever you find yourself writing lots of isSomething variables in your state, maybe it’s time to give statecharts a try!
  • 44. Further reading: Pure UI Control by Adam Solove https://medium.com/@asolove/ pure-ui-control-ac8d1be97a8d STATECHARTS: A VISUAL FORMALISM FOR COMPLEX SYSTEMS http://www.inf.ed.ac.uk/teaching/courses/seoc/2005_2006/ resources/statecharts.pdf You are managing state? Think twice. by Krasimir Tsonev http://krasimirtsonev.com/blog/article/managing-state-in- javascript-with-state-machines-stent Infinitely Better UIs with Finite Automata by David Khourshid https://www.youtube.com/watch?v=VU1NKX6Qkxc Rambling thoughts on React and Finite State Machines by Ryan Florence https://www.youtube.com/watch?v=MkdV2-U16tc