SlideShare a Scribd company logo
1 of 43
Download to read offline
DETERMINISTIC JS APPLICATIONS
State Management
A B O U T M E
{
"name": "Ilia Idakiev",
"experience": [
"Developer & Founder of HNS/HG“,
"Lecturer in 'Advanced JS' @ Sofia University”,
"Contractor / Consultant",
“Public / Private Courses“
],
"involvedIn": [
"Angular Sofia", "SofiaJS", "BeerJS"
]
}
ANGULAR SOFIA
26.01.2019 (Saturday)

10 AM – 1:30 PM

@ CampusX
“A deterministic system is a system in which no 
randomness is involved in the development of future
states of the system. A deterministic model will thus
always produce the same output from a given
starting condition or initial state.
wikipedia
“In computer programming, a pure function is a
function that:



1. Returns the same value for the same arguments.
2. Its evaluation has no side effects.
wikipedia
“An expression is called referentially transparent if
it can be replaced with its corresponding value
without changing the program's behavior. This
requires that the expression is pure.
wikipedia
Why?
BENEFITS OF WRITING REFERENTIAL TRANSPARENT CODE
• It’s easier to modify code without breaking it.

• It’s possible to apply optimisations like memoization, lazy-evaluation.

• Helps proving correctness. (It’s easier to reason about.)
Deterministic JavaScript Applications
REDUX
Deterministic JavaScript Applications
REDUX
Resource: https://itnext.io/integrating-semantic-ui-modal-with-redux-4df36abb755c
What should we put inside the REDUX store?
How to minimise our state?
Deterministic JavaScript Applications
STATE DERIVATIONS WITH SELECTORS (RESELECT)
• Selectors can compute derived data, allowing Redux to store the minimal possible
state.

• Selectors are efficient. A selector is not recomputed unless one of its arguments
changes.

• Selectors are composable. They can be used as input to other selectors.
How should we store data inside the REDUX store?
Deterministic JavaScript Applications
PROBLEMS WITH STATE SHAPE
• When a piece of data is duplicated in several places, it becomes harder to make sure that it is
updated appropriately.

• Nested data means that the corresponding reducer logic has to be more nested and therefore
more complex. In particular, trying to update a deeply nested field can become very ugly very
fast.

• Since immutable data updates require all ancestors in the state tree to be copied and updated
as well, and new object references will cause connected UI components to re-render, an
update to a deeply nested data object could force totally unrelated UI components to re-
render even if the data they're displaying hasn't actually changed.



• NORMALIZR - Normalises nested JSON according to a schema.
FIX:
Reusing reducer logic?
Deterministic JavaScript Applications
HIGH ORDER REDUCERS
• A higher-order reducer is a function that takes a reducer function as an argument,
and/or returns a new reducer function as a result. It can also be viewed as a
"reducer factory". 

• We can use this pattern to create specialized versions of our own reducer
functions, with each version only responding to specific actions.
How to make our application state persistent across browsers?
THE UNIFORM RESOURCE
LOCATOR (URL),
Deterministic JavaScript Applications
SINGLE PAGE APPLICATIONS
http://location/**/*
index.html
*
*without static assets like css, js files
Deterministic JavaScript Applications
HOW SINGLE PAGE APPLICATION NAVIGATION WORKS
• Each browser tab has a “browsing context”.

• The browsing context maintains a “session history”, which is basically, an array of
location entries
Deterministic JavaScript Applications
BROWSER HISTORY API
• pushState() - takes three parameters: a state object, a title (which is currently
ignored), and (optionally) a URL.

• replaceState() - operates exactly like pushState() except that it modifies the current
history entry instead of creating a new one.

• go() - method to load a specific page from session history, identified by its relative
position to the current page (with the current page being, of course, relative index 0).

• back() - like the back browser button.

• forward() - like the froward browser button.
Deterministic JavaScript Applications
BROWSER HISTORY API IN SPA
• <a href=“…”>Link</a> with event.preventDefault + pushState

• window.addEventListener(‘popstate’, changeRouteHandler)
Deterministic JavaScript Applications
ROUTER DYNAMIC PATTERN MATCHING
• A dynamic segment is denoted by a colon “:”
• When a route is matched, the value of the dynamic segments will be available for
use.
/user/:username/post/:post_id
Deterministic JavaScript Applications
UNIFORM RESOURCE LOCATOR
• a form of URI and a standardized naming convention for addressing documents
accessible over the Internet and Intranet.
Resource: https://medium.com/@pshrmn/demystifying-single-page-applications-3068d0555d46
Deterministic JavaScript Applications
UTILISING THE URL IN SINGLE PAGE APPLICATIONS
• Controlling UI components like Dialogs and Tabs using the URL path.

• Controlling the data and state of UI element like tables, dropdown.
• Application State Persistence
• Reducing Redux State
• More Deterministic Application
• Writing less code?
PROS CONS
• Longer and uglier URL
Deterministic JavaScript Applications
WHAT ARE WE TRYING TO ACHIEVE?
APPLICATION OUTPUTINPUT
(Pure function)
How will this work without side-effects?
Deterministic JavaScript Applications
SIDE EFFECTS
• Side effects are essential to enable a program to work with the outside world
(people, filesystems, networks).

• By abstracting the side-effects it’s easier for us to find and fix errors.



DEMO
Is REDUX enough?
After a while its very hard to follow
how and why state changes
happened when the state starts
growing bigger and bigger
“A finite-state machine (FSM) is an abstract
machine that can be in exactly one of a finite number
of states at any given time.
wikipedia
Deterministic JavaScript Applications
FINITE-STATE MACHINES
➤ Can change from one state to another in response to some external input.

➤ Are defined by a list of its states, its initial state, and the conditions for each state
transition.

➤ Can be of two types - deterministic and non-deterministic (but every non-
deterministic can be converted to deterministic)
Deterministic JavaScript Applications
DETERMINISTIC FINITE-STATE MACHINES
➤ each of its transitions is uniquely determined by its source state and input
symbol, and
➤ reading an input symbol is required for each state transition.
In automata theory, a finite state machine is called a deterministic finite
automaton (DFA), if
Deterministic JavaScript Applications
DETERMINISTIC FINITE-STATE MACHINES
a b c
STATECHARTS
Deterministic JavaScript Applications
STATECHARTS
➤ Extended state machine diagrams that allow us to model our states hierarchically.

➤ A compound state can be split up into completely separate orthogonal regions and
each region specifies its own state machine.

➤ States can have multiple transitions for the same event and transitions can be
guarded.

➤ Transitions can happen automatically and can be delayed.

➤ Statecharts keep history.
Resource: https://statecharts.github.io/
XSTATE
DEMO
Deterministic JavaScript Applications
XSTATE
➤ We can preview and simulate your statecharts with xstate visualizer.

➤ Eeasy to test all cases that our application can be in.
Resource: https://statecharts.github.io/
GitHub > https://github.com/iliaidakiev (/slides/ - list of future and past events)
Twitter > @ilia_idakiev
STATECHARTS
Deterministic JavaScript Applications
CONNECT
THANK YOU!

More Related Content

Similar to Deterministic JavaScript Applications

States, state graphs and transition testing
States, state graphs and transition testingStates, state graphs and transition testing
States, state graphs and transition testingABHISHEK KUMAR
 
Continuous Intelligence - Streaming Apps That Are Always In Sync | Simon Cros...
Continuous Intelligence - Streaming Apps That Are Always In Sync | Simon Cros...Continuous Intelligence - Streaming Apps That Are Always In Sync | Simon Cros...
Continuous Intelligence - Streaming Apps That Are Always In Sync | Simon Cros...HostedbyConfluent
 
CTS2 Development Framework In Action
CTS2 Development Framework In ActionCTS2 Development Framework In Action
CTS2 Development Framework In Actioncts2framework
 
Advanced web application architecture Way2Web
Advanced web application architecture Way2WebAdvanced web application architecture Way2Web
Advanced web application architecture Way2WebMatthias Noback
 
The Clean Architecture
The Clean ArchitectureThe Clean Architecture
The Clean ArchitectureDmytro Turskyi
 
Liftweb
LiftwebLiftweb
LiftwebScalac
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...Karmanjay Verma
 
How to – wrap soap web service around a database
How to – wrap soap web service around a databaseHow to – wrap soap web service around a database
How to – wrap soap web service around a databaseSon Nguyen
 
A load balancing model based on cloud partitioning for the public cloud. ppt
A  load balancing model based on cloud partitioning for the public cloud. ppt A  load balancing model based on cloud partitioning for the public cloud. ppt
A load balancing model based on cloud partitioning for the public cloud. ppt Lavanya Vigrahala
 
Software engineering rogers pressman chapter 7
Software engineering rogers pressman chapter 7Software engineering rogers pressman chapter 7
Software engineering rogers pressman chapter 7mohammad hossein Jalili
 
Hybrid Web Applications
Hybrid Web ApplicationsHybrid Web Applications
Hybrid Web ApplicationsJames Da Costa
 
Data Con LA 2022 - Event Sourcing with Apache Pulsar and Apache Quarkus
Data Con LA 2022 - Event Sourcing with Apache Pulsar and Apache QuarkusData Con LA 2022 - Event Sourcing with Apache Pulsar and Apache Quarkus
Data Con LA 2022 - Event Sourcing with Apache Pulsar and Apache QuarkusData Con LA
 
Java Web services
Java Web servicesJava Web services
Java Web servicesSujit Kumar
 
Taming the QIX Engine with Reactive Programming
Taming the QIX Engine with Reactive ProgrammingTaming the QIX Engine with Reactive Programming
Taming the QIX Engine with Reactive ProgrammingSperos Kokenes
 
Automate Software Change Estimation
Automate Software Change EstimationAutomate Software Change Estimation
Automate Software Change EstimationBrenda Barrioz, CPDS
 
Antelope: A Web service for publishing Life Cycle Assessment models and resul...
Antelope: A Web service for publishing Life Cycle Assessment models and resul...Antelope: A Web service for publishing Life Cycle Assessment models and resul...
Antelope: A Web service for publishing Life Cycle Assessment models and resul...Brandon Kuczenski
 
Full Stack Reactive In Practice
Full Stack Reactive In PracticeFull Stack Reactive In Practice
Full Stack Reactive In PracticeLightbend
 

Similar to Deterministic JavaScript Applications (20)

States, state graphs and transition testing
States, state graphs and transition testingStates, state graphs and transition testing
States, state graphs and transition testing
 
Potter’S Wheel
Potter’S WheelPotter’S Wheel
Potter’S Wheel
 
Continuous Intelligence - Streaming Apps That Are Always In Sync | Simon Cros...
Continuous Intelligence - Streaming Apps That Are Always In Sync | Simon Cros...Continuous Intelligence - Streaming Apps That Are Always In Sync | Simon Cros...
Continuous Intelligence - Streaming Apps That Are Always In Sync | Simon Cros...
 
CTS2 Development Framework In Action
CTS2 Development Framework In ActionCTS2 Development Framework In Action
CTS2 Development Framework In Action
 
Advanced web application architecture Way2Web
Advanced web application architecture Way2WebAdvanced web application architecture Way2Web
Advanced web application architecture Way2Web
 
The Clean Architecture
The Clean ArchitectureThe Clean Architecture
The Clean Architecture
 
Liftweb
LiftwebLiftweb
Liftweb
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
 
How to – wrap soap web service around a database
How to – wrap soap web service around a databaseHow to – wrap soap web service around a database
How to – wrap soap web service around a database
 
A load balancing model based on cloud partitioning for the public cloud. ppt
A  load balancing model based on cloud partitioning for the public cloud. ppt A  load balancing model based on cloud partitioning for the public cloud. ppt
A load balancing model based on cloud partitioning for the public cloud. ppt
 
Software engineering rogers pressman chapter 7
Software engineering rogers pressman chapter 7Software engineering rogers pressman chapter 7
Software engineering rogers pressman chapter 7
 
Lecture 12
Lecture 12Lecture 12
Lecture 12
 
Hybrid Web Applications
Hybrid Web ApplicationsHybrid Web Applications
Hybrid Web Applications
 
Data Con LA 2022 - Event Sourcing with Apache Pulsar and Apache Quarkus
Data Con LA 2022 - Event Sourcing with Apache Pulsar and Apache QuarkusData Con LA 2022 - Event Sourcing with Apache Pulsar and Apache Quarkus
Data Con LA 2022 - Event Sourcing with Apache Pulsar and Apache Quarkus
 
Java Web services
Java Web servicesJava Web services
Java Web services
 
Taming the QIX Engine with Reactive Programming
Taming the QIX Engine with Reactive ProgrammingTaming the QIX Engine with Reactive Programming
Taming the QIX Engine with Reactive Programming
 
Automate Software Change Estimation
Automate Software Change EstimationAutomate Software Change Estimation
Automate Software Change Estimation
 
Antelope: A Web service for publishing Life Cycle Assessment models and resul...
Antelope: A Web service for publishing Life Cycle Assessment models and resul...Antelope: A Web service for publishing Life Cycle Assessment models and resul...
Antelope: A Web service for publishing Life Cycle Assessment models and resul...
 
TY.BSc.IT Java QB U6
TY.BSc.IT Java QB U6TY.BSc.IT Java QB U6
TY.BSc.IT Java QB U6
 
Full Stack Reactive In Practice
Full Stack Reactive In PracticeFull Stack Reactive In Practice
Full Stack Reactive In Practice
 

More from Ilia Idakiev

No more promises lets RxJS 2 Edit
No more promises lets RxJS 2 EditNo more promises lets RxJS 2 Edit
No more promises lets RxJS 2 EditIlia Idakiev
 
Enterprise State Management with NGRX/platform
Enterprise State Management with NGRX/platformEnterprise State Management with NGRX/platform
Enterprise State Management with NGRX/platformIlia Idakiev
 
Deep Dive into Zone.JS
Deep Dive into Zone.JSDeep Dive into Zone.JS
Deep Dive into Zone.JSIlia Idakiev
 
RxJS Schedulers - Controlling Time
RxJS Schedulers - Controlling TimeRxJS Schedulers - Controlling Time
RxJS Schedulers - Controlling TimeIlia Idakiev
 
Creating lightweight JS Apps w/ Web Components and lit-html
Creating lightweight JS Apps w/ Web Components and lit-htmlCreating lightweight JS Apps w/ Web Components and lit-html
Creating lightweight JS Apps w/ Web Components and lit-htmlIlia Idakiev
 
No More Promises! Let's RxJS!
No More Promises! Let's RxJS!No More Promises! Let's RxJS!
No More Promises! Let's RxJS!Ilia Idakiev
 
Marble Testing RxJS streams
Marble Testing RxJS streamsMarble Testing RxJS streams
Marble Testing RxJS streamsIlia Idakiev
 
Web Components Everywhere
Web Components EverywhereWeb Components Everywhere
Web Components EverywhereIlia Idakiev
 
Building Reusable Custom Elements With Angular
Building Reusable Custom Elements With AngularBuilding Reusable Custom Elements With Angular
Building Reusable Custom Elements With AngularIlia Idakiev
 
State management for enterprise angular applications
State management for enterprise angular applicationsState management for enterprise angular applications
State management for enterprise angular applicationsIlia Idakiev
 
Offline progressive web apps with NodeJS and React
Offline progressive web apps with NodeJS and ReactOffline progressive web apps with NodeJS and React
Offline progressive web apps with NodeJS and ReactIlia Idakiev
 
Testing rx js using marbles within angular
Testing rx js using marbles within angularTesting rx js using marbles within angular
Testing rx js using marbles within angularIlia Idakiev
 
Predictable reactive state management for enterprise apps using NGRX/platform
Predictable reactive state management for enterprise apps using NGRX/platformPredictable reactive state management for enterprise apps using NGRX/platform
Predictable reactive state management for enterprise apps using NGRX/platformIlia Idakiev
 
Angular server side rendering with NodeJS - In Pursuit Of Speed
Angular server side rendering with NodeJS - In Pursuit Of SpeedAngular server side rendering with NodeJS - In Pursuit Of Speed
Angular server side rendering with NodeJS - In Pursuit Of SpeedIlia Idakiev
 
Angular Offline Progressive Web Apps With NodeJS
Angular Offline Progressive Web Apps With NodeJSAngular Offline Progressive Web Apps With NodeJS
Angular Offline Progressive Web Apps With NodeJSIlia Idakiev
 
Introduction to Offline Progressive Web Applications
Introduction to Offline Progressive Web ApplicationsIntroduction to Offline Progressive Web Applications
Introduction to Offline Progressive Web ApplicationsIlia Idakiev
 
Reflective injection using TypeScript
Reflective injection using TypeScriptReflective injection using TypeScript
Reflective injection using TypeScriptIlia Idakiev
 

More from Ilia Idakiev (18)

No more promises lets RxJS 2 Edit
No more promises lets RxJS 2 EditNo more promises lets RxJS 2 Edit
No more promises lets RxJS 2 Edit
 
Enterprise State Management with NGRX/platform
Enterprise State Management with NGRX/platformEnterprise State Management with NGRX/platform
Enterprise State Management with NGRX/platform
 
Deep Dive into Zone.JS
Deep Dive into Zone.JSDeep Dive into Zone.JS
Deep Dive into Zone.JS
 
RxJS Schedulers - Controlling Time
RxJS Schedulers - Controlling TimeRxJS Schedulers - Controlling Time
RxJS Schedulers - Controlling Time
 
Creating lightweight JS Apps w/ Web Components and lit-html
Creating lightweight JS Apps w/ Web Components and lit-htmlCreating lightweight JS Apps w/ Web Components and lit-html
Creating lightweight JS Apps w/ Web Components and lit-html
 
No More Promises! Let's RxJS!
No More Promises! Let's RxJS!No More Promises! Let's RxJS!
No More Promises! Let's RxJS!
 
Marble Testing RxJS streams
Marble Testing RxJS streamsMarble Testing RxJS streams
Marble Testing RxJS streams
 
Web Components Everywhere
Web Components EverywhereWeb Components Everywhere
Web Components Everywhere
 
Building Reusable Custom Elements With Angular
Building Reusable Custom Elements With AngularBuilding Reusable Custom Elements With Angular
Building Reusable Custom Elements With Angular
 
State management for enterprise angular applications
State management for enterprise angular applicationsState management for enterprise angular applications
State management for enterprise angular applications
 
Offline progressive web apps with NodeJS and React
Offline progressive web apps with NodeJS and ReactOffline progressive web apps with NodeJS and React
Offline progressive web apps with NodeJS and React
 
Testing rx js using marbles within angular
Testing rx js using marbles within angularTesting rx js using marbles within angular
Testing rx js using marbles within angular
 
Predictable reactive state management for enterprise apps using NGRX/platform
Predictable reactive state management for enterprise apps using NGRX/platformPredictable reactive state management for enterprise apps using NGRX/platform
Predictable reactive state management for enterprise apps using NGRX/platform
 
Angular server side rendering with NodeJS - In Pursuit Of Speed
Angular server side rendering with NodeJS - In Pursuit Of SpeedAngular server side rendering with NodeJS - In Pursuit Of Speed
Angular server side rendering with NodeJS - In Pursuit Of Speed
 
Angular Offline Progressive Web Apps With NodeJS
Angular Offline Progressive Web Apps With NodeJSAngular Offline Progressive Web Apps With NodeJS
Angular Offline Progressive Web Apps With NodeJS
 
Introduction to Offline Progressive Web Applications
Introduction to Offline Progressive Web ApplicationsIntroduction to Offline Progressive Web Applications
Introduction to Offline Progressive Web Applications
 
Reflective injection using TypeScript
Reflective injection using TypeScriptReflective injection using TypeScript
Reflective injection using TypeScript
 
Zone.js
Zone.jsZone.js
Zone.js
 

Recently uploaded

Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 

Recently uploaded (20)

Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 

Deterministic JavaScript Applications

  • 2. A B O U T M E { "name": "Ilia Idakiev", "experience": [ "Developer & Founder of HNS/HG“, "Lecturer in 'Advanced JS' @ Sofia University”, "Contractor / Consultant", “Public / Private Courses“ ], "involvedIn": [ "Angular Sofia", "SofiaJS", "BeerJS" ] }
  • 4. 26.01.2019 (Saturday)
 10 AM – 1:30 PM
 @ CampusX
  • 5. “A deterministic system is a system in which no  randomness is involved in the development of future states of the system. A deterministic model will thus always produce the same output from a given starting condition or initial state. wikipedia
  • 6. “In computer programming, a pure function is a function that:
 
 1. Returns the same value for the same arguments. 2. Its evaluation has no side effects. wikipedia
  • 7. “An expression is called referentially transparent if it can be replaced with its corresponding value without changing the program's behavior. This requires that the expression is pure. wikipedia
  • 9. BENEFITS OF WRITING REFERENTIAL TRANSPARENT CODE • It’s easier to modify code without breaking it.
 • It’s possible to apply optimisations like memoization, lazy-evaluation.
 • Helps proving correctness. (It’s easier to reason about.) Deterministic JavaScript Applications
  • 10. REDUX
  • 11. Deterministic JavaScript Applications REDUX Resource: https://itnext.io/integrating-semantic-ui-modal-with-redux-4df36abb755c
  • 12. What should we put inside the REDUX store?
  • 13. How to minimise our state?
  • 14. Deterministic JavaScript Applications STATE DERIVATIONS WITH SELECTORS (RESELECT) • Selectors can compute derived data, allowing Redux to store the minimal possible state.
 • Selectors are efficient. A selector is not recomputed unless one of its arguments changes.
 • Selectors are composable. They can be used as input to other selectors.
  • 15. How should we store data inside the REDUX store?
  • 16. Deterministic JavaScript Applications PROBLEMS WITH STATE SHAPE • When a piece of data is duplicated in several places, it becomes harder to make sure that it is updated appropriately.
 • Nested data means that the corresponding reducer logic has to be more nested and therefore more complex. In particular, trying to update a deeply nested field can become very ugly very fast.
 • Since immutable data updates require all ancestors in the state tree to be copied and updated as well, and new object references will cause connected UI components to re-render, an update to a deeply nested data object could force totally unrelated UI components to re- render even if the data they're displaying hasn't actually changed.
 
 • NORMALIZR - Normalises nested JSON according to a schema. FIX:
  • 18. Deterministic JavaScript Applications HIGH ORDER REDUCERS • A higher-order reducer is a function that takes a reducer function as an argument, and/or returns a new reducer function as a result. It can also be viewed as a "reducer factory". 
 • We can use this pattern to create specialized versions of our own reducer functions, with each version only responding to specific actions.
  • 19. How to make our application state persistent across browsers?
  • 21. Deterministic JavaScript Applications SINGLE PAGE APPLICATIONS http://location/**/* index.html * *without static assets like css, js files
  • 22. Deterministic JavaScript Applications HOW SINGLE PAGE APPLICATION NAVIGATION WORKS • Each browser tab has a “browsing context”.
 • The browsing context maintains a “session history”, which is basically, an array of location entries
  • 23. Deterministic JavaScript Applications BROWSER HISTORY API • pushState() - takes three parameters: a state object, a title (which is currently ignored), and (optionally) a URL.
 • replaceState() - operates exactly like pushState() except that it modifies the current history entry instead of creating a new one.
 • go() - method to load a specific page from session history, identified by its relative position to the current page (with the current page being, of course, relative index 0).
 • back() - like the back browser button.
 • forward() - like the froward browser button.
  • 24. Deterministic JavaScript Applications BROWSER HISTORY API IN SPA • <a href=“…”>Link</a> with event.preventDefault + pushState
 • window.addEventListener(‘popstate’, changeRouteHandler)
  • 25. Deterministic JavaScript Applications ROUTER DYNAMIC PATTERN MATCHING • A dynamic segment is denoted by a colon “:” • When a route is matched, the value of the dynamic segments will be available for use. /user/:username/post/:post_id
  • 26. Deterministic JavaScript Applications UNIFORM RESOURCE LOCATOR • a form of URI and a standardized naming convention for addressing documents accessible over the Internet and Intranet. Resource: https://medium.com/@pshrmn/demystifying-single-page-applications-3068d0555d46
  • 27. Deterministic JavaScript Applications UTILISING THE URL IN SINGLE PAGE APPLICATIONS • Controlling UI components like Dialogs and Tabs using the URL path.
 • Controlling the data and state of UI element like tables, dropdown. • Application State Persistence • Reducing Redux State • More Deterministic Application • Writing less code? PROS CONS • Longer and uglier URL
  • 28. Deterministic JavaScript Applications WHAT ARE WE TRYING TO ACHIEVE? APPLICATION OUTPUTINPUT (Pure function)
  • 29. How will this work without side-effects?
  • 30. Deterministic JavaScript Applications SIDE EFFECTS • Side effects are essential to enable a program to work with the outside world (people, filesystems, networks).
 • By abstracting the side-effects it’s easier for us to find and fix errors.
 

  • 31. DEMO
  • 32. Is REDUX enough? After a while its very hard to follow how and why state changes happened when the state starts growing bigger and bigger
  • 33. “A finite-state machine (FSM) is an abstract machine that can be in exactly one of a finite number of states at any given time. wikipedia
  • 34. Deterministic JavaScript Applications FINITE-STATE MACHINES ➤ Can change from one state to another in response to some external input.
 ➤ Are defined by a list of its states, its initial state, and the conditions for each state transition.
 ➤ Can be of two types - deterministic and non-deterministic (but every non- deterministic can be converted to deterministic)
  • 35. Deterministic JavaScript Applications DETERMINISTIC FINITE-STATE MACHINES ➤ each of its transitions is uniquely determined by its source state and input symbol, and ➤ reading an input symbol is required for each state transition. In automata theory, a finite state machine is called a deterministic finite automaton (DFA), if
  • 38. Deterministic JavaScript Applications STATECHARTS ➤ Extended state machine diagrams that allow us to model our states hierarchically.
 ➤ A compound state can be split up into completely separate orthogonal regions and each region specifies its own state machine.
 ➤ States can have multiple transitions for the same event and transitions can be guarded.
 ➤ Transitions can happen automatically and can be delayed.
 ➤ Statecharts keep history. Resource: https://statecharts.github.io/
  • 40. DEMO
  • 41. Deterministic JavaScript Applications XSTATE ➤ We can preview and simulate your statecharts with xstate visualizer.
 ➤ Eeasy to test all cases that our application can be in. Resource: https://statecharts.github.io/
  • 42. GitHub > https://github.com/iliaidakiev (/slides/ - list of future and past events) Twitter > @ilia_idakiev STATECHARTS Deterministic JavaScript Applications CONNECT