SlideShare a Scribd company logo

Are statecharts the next big UI paradigm?

Statecharts (aka state-machines) have been used in UI development for decades. This talk will explain how they work in comparison with other state-management paradigms such as Redux. I will dive into the pros and cons of statecharts and provide in depth examples of how they can be used with React.

Are statecharts the next big UI paradigm?

Statecharts (aka state-machines) have been used in UI development for decades. This talk will explain how they work in comparison with other state-management paradigms such as Redux. I will dive into the pros and cons of statecharts and provide in depth examples of how they can be used with React.

Are statecharts the next big UI paradigm?

1 of 45

Recommended

State management in react applications (Statecharts) by
State management in react applications (Statecharts)State management in react applications (Statecharts)
State management in react applications (Statecharts)Tomáš Drenčák
355 views26 slides
Android Data Storagefinal by
Android Data StoragefinalAndroid Data Storagefinal
Android Data StoragefinalNakka Srilakshmi
612 views35 slides
Hibernate by
HibernateHibernate
HibernatePrashant Kalkar
846 views74 slides
Javascript by
JavascriptJavascript
Javascriptmussawir20
4.5K views71 slides
Basic JavaScript Tutorial by
Basic JavaScript TutorialBasic JavaScript Tutorial
Basic JavaScript TutorialDHTMLExtreme
3.8K views134 slides
Java script Basic by
Java script BasicJava script Basic
Java script BasicJaya Kumari
172 views75 slides
Async History - javascript by
Async History - javascriptAsync History - javascript
Async History - javascriptNishchit Dhanani
1.9K views20 slides
React Internals - How understanding React implementation can help us write be... by
React Internals - How understanding React implementation can help us write be...React Internals - How understanding React implementation can help us write be...
React Internals - How understanding React implementation can help us write be...Ankit Muchhala
1.9K views50 slides

More Related Content

What's hot

SOLID Java Code by
SOLID Java CodeSOLID Java Code
SOLID Java CodeOmar Bashir
2.8K views53 slides
9. ES6 | Let And Const | TypeScript | JavaScript by
9. ES6 | Let And Const | TypeScript | JavaScript9. ES6 | Let And Const | TypeScript | JavaScript
9. ES6 | Let And Const | TypeScript | JavaScriptpcnmtutorials
515 views11 slides
Java script final presentation by
Java script final presentationJava script final presentation
Java script final presentationAdhoura Academy
3.8K views51 slides
transforming xml using xsl and xslt by
transforming xml using xsl and xslttransforming xml using xsl and xslt
transforming xml using xsl and xsltHemant Suthar
2.3K views12 slides
Concurrency With Go by
Concurrency With GoConcurrency With Go
Concurrency With GoJohn-Alan Simmons
1.5K views16 slides
React + Redux Introduction by
React + Redux IntroductionReact + Redux Introduction
React + Redux IntroductionNikolaus Graf
25.7K views47 slides
Introduction to hibernate by
Introduction to hibernateIntroduction to hibernate
Introduction to hibernatehr1383
7.3K views20 slides
Flutter State Management Using GetX.pdf by
Flutter State Management Using GetX.pdfFlutter State Management Using GetX.pdf
Flutter State Management Using GetX.pdfKaty Slemon
1.6K views36 slides
Javascript event handler by
Javascript event handlerJavascript event handler
Javascript event handlerJesus Obenita Jr.
4.4K views13 slides
Introduction to java netbeans by
Introduction to java netbeansIntroduction to java netbeans
Introduction to java netbeansShrey Goswami
5.5K views21 slides
JavaScript Basic by
JavaScript BasicJavaScript Basic
JavaScript BasicFinsa Nurpandi
290 views41 slides
Java swing by
Java swingJava swing
Java swingApurbo Datta
11.3K views46 slides
Understanding the cloud computing stack by
Understanding the cloud computing stackUnderstanding the cloud computing stack
Understanding the cloud computing stackSatish Chavan
1.5K views23 slides
DDD - What, why, how? by
DDD - What, why, how?DDD - What, why, how?
DDD - What, why, how?Alexey Zimarev
4.3K views58 slides
Java script by
Java scriptJava script
Java scriptSadeek Mohammed
3.7K views49 slides
JavaScript & Dom Manipulation by
JavaScript & Dom ManipulationJavaScript & Dom Manipulation
JavaScript & Dom ManipulationMohammed Arif
7.9K views24 slides
Introduction to Basic Concepts in Web by
Introduction to Basic Concepts in WebIntroduction to Basic Concepts in Web
Introduction to Basic Concepts in WebJussi Pohjolainen
4.8K views23 slides
Java script by
Java scriptJava script
Java scriptShyam Khant
2.8K views161 slides

What's hot (20)

SOLID Java Code by Omar Bashir
SOLID Java CodeSOLID Java Code
SOLID Java Code
Omar Bashir2.8K views
9. ES6 | Let And Const | TypeScript | JavaScript by pcnmtutorials
9. ES6 | Let And Const | TypeScript | JavaScript9. ES6 | Let And Const | TypeScript | JavaScript
9. ES6 | Let And Const | TypeScript | JavaScript
pcnmtutorials515 views
Java script final presentation by Adhoura Academy
Java script final presentationJava script final presentation
Java script final presentation
Adhoura Academy3.8K views
transforming xml using xsl and xslt by Hemant Suthar
transforming xml using xsl and xslttransforming xml using xsl and xslt
transforming xml using xsl and xslt
Hemant Suthar2.3K views
React + Redux Introduction by Nikolaus Graf
React + Redux IntroductionReact + Redux Introduction
React + Redux Introduction
Nikolaus Graf25.7K views
Introduction to hibernate by hr1383
Introduction to hibernateIntroduction to hibernate
Introduction to hibernate
hr13837.3K views
Flutter State Management Using GetX.pdf by Katy Slemon
Flutter State Management Using GetX.pdfFlutter State Management Using GetX.pdf
Flutter State Management Using GetX.pdf
Katy Slemon1.6K views
Introduction to java netbeans by Shrey Goswami
Introduction to java netbeansIntroduction to java netbeans
Introduction to java netbeans
Shrey Goswami5.5K views
Understanding the cloud computing stack by Satish Chavan
Understanding the cloud computing stackUnderstanding the cloud computing stack
Understanding the cloud computing stack
Satish Chavan1.5K views
JavaScript & Dom Manipulation by Mohammed Arif
JavaScript & Dom ManipulationJavaScript & Dom Manipulation
JavaScript & Dom Manipulation
Mohammed Arif7.9K views
Introduction to Basic Concepts in Web by Jussi Pohjolainen
Introduction to Basic Concepts in WebIntroduction to Basic Concepts in Web
Introduction to Basic Concepts in Web
Jussi Pohjolainen4.8K views

Similar to Are statecharts the next big UI paradigm?

A Journey with React by
A Journey with ReactA Journey with React
A Journey with ReactFITC
1K views54 slides
iOS 개발자의 Flutter 체험기 by
iOS 개발자의 Flutter 체험기iOS 개발자의 Flutter 체험기
iOS 개발자의 Flutter 체험기Wanbok Choi
1.5K views80 slides
N Things You Don't Want to Repeat in React Native by
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 NativeAnton Kulyk
225 views30 slides
Extending Redux in the Server Side by
Extending Redux in the Server SideExtending Redux in the Server Side
Extending Redux in the Server SideIgnacio Martín
1.2K views87 slides
Frontin like-a-backer by
Frontin like-a-backerFrontin like-a-backer
Frontin like-a-backerFrank de Jonge
10.6K views91 slides
How Reactive do we need to be by
How Reactive do we need to beHow Reactive do we need to be
How Reactive do we need to beJana Karceska
103 views26 slides
The accidental web designer - No Code Conf 2019 Workshop by
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 WorkshopWebflow
642 views47 slides
A short tale about state machine by
A short tale about state machineA short tale about state machine
A short tale about state machineŁukasz Chruściel
118 views86 slides
Advanced redux by
Advanced reduxAdvanced redux
Advanced reduxBoris Dinkevich
597 views102 slides
Introduction to Redux by
Introduction to ReduxIntroduction to Redux
Introduction to ReduxIgnacio Martín
7.6K views57 slides
The biggest lies about react hooks by
The biggest lies about react hooksThe biggest lies about react hooks
The biggest lies about react hooksMarios Fakiolas
114 views64 slides
Roman Schejbal: From Madness To Reason by
Roman Schejbal: From Madness To ReasonRoman Schejbal: From Madness To Reason
Roman Schejbal: From Madness To ReasonDevelcz
100 views49 slides
Imagine a world without mocks by
Imagine a world without mocksImagine a world without mocks
Imagine a world without mockskenbot
5.8K views79 slides
Serverless Functions and Vue.js by
Serverless Functions and Vue.jsServerless Functions and Vue.js
Serverless Functions and Vue.jsSarah Drasner
512 views72 slides
The Functional Programming Toolkit (NDC Oslo 2019) by
The Functional Programming Toolkit (NDC Oslo 2019)The Functional Programming Toolkit (NDC Oslo 2019)
The Functional Programming Toolkit (NDC Oslo 2019)Scott Wlaschin
6.3K views261 slides
Let it crash - fault tolerance in Elixir/OTP by
Let it crash - fault tolerance in Elixir/OTPLet it crash - fault tolerance in Elixir/OTP
Let it crash - fault tolerance in Elixir/OTPMaciej Kaszubowski
378 views86 slides
The evolution of asynchronous JavaScript by
The evolution of asynchronous JavaScriptThe evolution of asynchronous JavaScript
The evolution of asynchronous JavaScriptAlessandro Cinelli (cirpo)
2.6K views121 slides
Do I need tests when I have the compiler - Andrzej Jóźwiak - TomTom Dev Day 2020 by
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 2020Andrzej Jóźwiak
33 views55 slides
Getting the Most Out of jQuery Widgets by
Getting the Most Out of jQuery WidgetsGetting the Most Out of jQuery Widgets
Getting the Most Out of jQuery Widgetsvelveeta_512
5K views51 slides
You promise? by
You promise?You promise?
You promise?IT Weekend
1K views39 slides

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

A Journey with React by FITC
A Journey with ReactA Journey with React
A Journey with React
FITC1K views
iOS 개발자의 Flutter 체험기 by Wanbok Choi
iOS 개발자의 Flutter 체험기iOS 개발자의 Flutter 체험기
iOS 개발자의 Flutter 체험기
Wanbok Choi1.5K views
N Things You Don't Want to Repeat in React Native by Anton Kulyk
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 Kulyk225 views
Extending Redux in the Server Side by Ignacio Martín
Extending Redux in the Server SideExtending Redux in the Server Side
Extending Redux in the Server Side
Ignacio Martín1.2K views
How Reactive do we need to be by Jana Karceska
How Reactive do we need to beHow Reactive do we need to be
How Reactive do we need to be
Jana Karceska103 views
The accidental web designer - No Code Conf 2019 Workshop by Webflow
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
Webflow642 views
The biggest lies about react hooks by Marios Fakiolas
The biggest lies about react hooksThe biggest lies about react hooks
The biggest lies about react hooks
Marios Fakiolas114 views
Roman Schejbal: From Madness To Reason by Develcz
Roman Schejbal: From Madness To ReasonRoman Schejbal: From Madness To Reason
Roman Schejbal: From Madness To Reason
Develcz100 views
Imagine a world without mocks by kenbot
Imagine a world without mocksImagine a world without mocks
Imagine a world without mocks
kenbot5.8K views
Serverless Functions and Vue.js by Sarah Drasner
Serverless Functions and Vue.jsServerless Functions and Vue.js
Serverless Functions and Vue.js
Sarah Drasner512 views
The Functional Programming Toolkit (NDC Oslo 2019) by Scott Wlaschin
The Functional Programming Toolkit (NDC Oslo 2019)The Functional Programming Toolkit (NDC Oslo 2019)
The Functional Programming Toolkit (NDC Oslo 2019)
Scott Wlaschin6.3K views
Let it crash - fault tolerance in Elixir/OTP by Maciej Kaszubowski
Let it crash - fault tolerance in Elixir/OTPLet it crash - fault tolerance in Elixir/OTP
Let it crash - fault tolerance in Elixir/OTP
Maciej Kaszubowski378 views
Do I need tests when I have the compiler - Andrzej Jóźwiak - TomTom Dev Day 2020 by Andrzej Jóźwiak
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 by velveeta_512
Getting the Most Out of jQuery WidgetsGetting the Most Out of jQuery Widgets
Getting the Most Out of jQuery Widgets
velveeta_5125K views

Recently uploaded

Unveiling the Future: Groundbreaking Tech Innovations and Industry Insights o... by
Unveiling the Future: Groundbreaking Tech Innovations and Industry Insights o...Unveiling the Future: Groundbreaking Tech Innovations and Industry Insights o...
Unveiling the Future: Groundbreaking Tech Innovations and Industry Insights o...yamunashanmugam1997
6 views2 slides
Revised IASW Storyboard by
Revised IASW StoryboardRevised IASW Storyboard
Revised IASW Storyboardehclark63
0 views15 slides
Generative AI con Amazon Bedrock.pdf by
Generative AI con Amazon Bedrock.pdfGenerative AI con Amazon Bedrock.pdf
Generative AI con Amazon Bedrock.pdfGuido Maria Nebiolo
58 views48 slides
PRODUCT RESEARCH.pdf by
PRODUCT RESEARCH.pdfPRODUCT RESEARCH.pdf
PRODUCT RESEARCH.pdffreelancecribe
99 views15 slides
Fire-Resistant Cable Sizing of conductors supplying electrical equipment that... by
Fire-Resistant Cable Sizing of conductors supplying electrical equipment that...Fire-Resistant Cable Sizing of conductors supplying electrical equipment that...
Fire-Resistant Cable Sizing of conductors supplying electrical equipment that...fernando nuño
89 views15 slides
Non-Woven and their manufacturing process associated with the different appli... by
Non-Woven and their manufacturing process associated with the different appli...Non-Woven and their manufacturing process associated with the different appli...
Non-Woven and their manufacturing process associated with the different appli...ahmadkhobab18
9 views42 slides
1 - Introduction of Azure DevOps by
1 - Introduction of Azure DevOps1 - Introduction of Azure DevOps
1 - Introduction of Azure DevOpsBhaumik Patel
32 views30 slides
External errors in photogrammetry(khushi arora)_2.pptx by
External errors in photogrammetry(khushi arora)_2.pptxExternal errors in photogrammetry(khushi arora)_2.pptx
External errors in photogrammetry(khushi arora)_2.pptxkhushigisprofessiona
8 views13 slides
Agile Mumbai 2023 | AI-Powered Agility: A New Era of Sustainable Business Inn... by
Agile Mumbai 2023 | AI-Powered Agility: A New Era of Sustainable Business Inn...Agile Mumbai 2023 | AI-Powered Agility: A New Era of Sustainable Business Inn...
Agile Mumbai 2023 | AI-Powered Agility: A New Era of Sustainable Business Inn...AgileNetwork
9 views20 slides
Queue Management System.ppt by
Queue Management System.pptQueue Management System.ppt
Queue Management System.pptAddsoft Technologies Pvt. Ltd
15 views7 slides
European Copper Institute position on Transformers Regulation revision - Sept... by
European Copper Institute position on Transformers Regulation revision - Sept...European Copper Institute position on Transformers Regulation revision - Sept...
European Copper Institute position on Transformers Regulation revision - Sept...fernando nuño
108 views9 slides
Defined Capital - Mapping the AI Revolution and State of Adoption.pdf by
Defined Capital - Mapping the AI Revolution and State of Adoption.pdfDefined Capital - Mapping the AI Revolution and State of Adoption.pdf
Defined Capital - Mapping the AI Revolution and State of Adoption.pdfDefined Capital
18 views19 slides
The Future of Gas Analyzers by
The Future of Gas AnalyzersThe Future of Gas Analyzers
The Future of Gas AnalyzersEnviro Solutions Technology
13 views6 slides
The Significance of Regression Testing in Software Development.pdf by
The Significance of Regression Testing in Software Development.pdfThe Significance of Regression Testing in Software Development.pdf
The Significance of Regression Testing in Software Development.pdfRohitBhandari66
2 views9 slides
Why Is It Important To Periodically Analyze Your Generator Fluid by
Why Is It Important To Periodically Analyze Your Generator FluidWhy Is It Important To Periodically Analyze Your Generator Fluid
Why Is It Important To Periodically Analyze Your Generator FluidLeddy Power Systems Inc
8 views31 slides
AWS reInvent 2023 re:Cap services Slide deck by
AWS reInvent 2023 re:Cap services Slide deckAWS reInvent 2023 re:Cap services Slide deck
AWS reInvent 2023 re:Cap services Slide deckSammy Cheung
2 views50 slides
Kanban India 2023 | Dilip Mysore Devaraj | Efficient Deployment Flow with Dev... by
Kanban India 2023 | Dilip Mysore Devaraj | Efficient Deployment Flow with Dev...Kanban India 2023 | Dilip Mysore Devaraj | Efficient Deployment Flow with Dev...
Kanban India 2023 | Dilip Mysore Devaraj | Efficient Deployment Flow with Dev...LeanKanbanIndia
4 views13 slides
top-50-cybersecurity-threats.pdf by
top-50-cybersecurity-threats.pdftop-50-cybersecurity-threats.pdf
top-50-cybersecurity-threats.pdfnowplanettv1
42 views101 slides
Sky Tech veracity ISO 9001 Quality Management System by
Sky Tech veracity ISO 9001 Quality Management SystemSky Tech veracity ISO 9001 Quality Management System
Sky Tech veracity ISO 9001 Quality Management SystemAjayChaudhary937320
51 views1 slide
The Potential Of School Email List Marketing.pptx by
The Potential Of School Email List Marketing.pptxThe Potential Of School Email List Marketing.pptx
The Potential Of School Email List Marketing.pptxarishmakevinmax
9 views7 slides

Recently uploaded (20)

Unveiling the Future: Groundbreaking Tech Innovations and Industry Insights o... by yamunashanmugam1997
Unveiling the Future: Groundbreaking Tech Innovations and Industry Insights o...Unveiling the Future: Groundbreaking Tech Innovations and Industry Insights o...
Unveiling the Future: Groundbreaking Tech Innovations and Industry Insights o...
Revised IASW Storyboard by ehclark63
Revised IASW StoryboardRevised IASW Storyboard
Revised IASW Storyboard
ehclark630 views
Fire-Resistant Cable Sizing of conductors supplying electrical equipment that... by fernando nuño
Fire-Resistant Cable Sizing of conductors supplying electrical equipment that...Fire-Resistant Cable Sizing of conductors supplying electrical equipment that...
Fire-Resistant Cable Sizing of conductors supplying electrical equipment that...
fernando nuño89 views
Non-Woven and their manufacturing process associated with the different appli... by ahmadkhobab18
Non-Woven and their manufacturing process associated with the different appli...Non-Woven and their manufacturing process associated with the different appli...
Non-Woven and their manufacturing process associated with the different appli...
ahmadkhobab189 views
1 - Introduction of Azure DevOps by Bhaumik Patel
1 - Introduction of Azure DevOps1 - Introduction of Azure DevOps
1 - Introduction of Azure DevOps
Bhaumik Patel32 views
Agile Mumbai 2023 | AI-Powered Agility: A New Era of Sustainable Business Inn... by AgileNetwork
Agile Mumbai 2023 | AI-Powered Agility: A New Era of Sustainable Business Inn...Agile Mumbai 2023 | AI-Powered Agility: A New Era of Sustainable Business Inn...
Agile Mumbai 2023 | AI-Powered Agility: A New Era of Sustainable Business Inn...
AgileNetwork9 views
European Copper Institute position on Transformers Regulation revision - Sept... by fernando nuño
European Copper Institute position on Transformers Regulation revision - Sept...European Copper Institute position on Transformers Regulation revision - Sept...
European Copper Institute position on Transformers Regulation revision - Sept...
fernando nuño108 views
Defined Capital - Mapping the AI Revolution and State of Adoption.pdf by Defined Capital
Defined Capital - Mapping the AI Revolution and State of Adoption.pdfDefined Capital - Mapping the AI Revolution and State of Adoption.pdf
Defined Capital - Mapping the AI Revolution and State of Adoption.pdf
Defined Capital18 views
The Significance of Regression Testing in Software Development.pdf by RohitBhandari66
The Significance of Regression Testing in Software Development.pdfThe Significance of Regression Testing in Software Development.pdf
The Significance of Regression Testing in Software Development.pdf
RohitBhandari662 views
AWS reInvent 2023 re:Cap services Slide deck by Sammy Cheung
AWS reInvent 2023 re:Cap services Slide deckAWS reInvent 2023 re:Cap services Slide deck
AWS reInvent 2023 re:Cap services Slide deck
Sammy Cheung2 views
Kanban India 2023 | Dilip Mysore Devaraj | Efficient Deployment Flow with Dev... by LeanKanbanIndia
Kanban India 2023 | Dilip Mysore Devaraj | Efficient Deployment Flow with Dev...Kanban India 2023 | Dilip Mysore Devaraj | Efficient Deployment Flow with Dev...
Kanban India 2023 | Dilip Mysore Devaraj | Efficient Deployment Flow with Dev...
LeanKanbanIndia4 views
top-50-cybersecurity-threats.pdf by nowplanettv1
top-50-cybersecurity-threats.pdftop-50-cybersecurity-threats.pdf
top-50-cybersecurity-threats.pdf
nowplanettv142 views
Sky Tech veracity ISO 9001 Quality Management System by AjayChaudhary937320
Sky Tech veracity ISO 9001 Quality Management SystemSky Tech veracity ISO 9001 Quality Management System
Sky Tech veracity ISO 9001 Quality Management System
The Potential Of School Email List Marketing.pptx by arishmakevinmax
The Potential Of School Email List Marketing.pptxThe Potential Of School Email List Marketing.pptx
The Potential Of School Email List Marketing.pptx
arishmakevinmax9 views

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.
  • 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
  • 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.
  • 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.
  • 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