SlideShare a Scribd company logo
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!
Ad

More Related Content

Similar to Deterministic JavaScript Applications (20)

6 10-presentation
6 10-presentation6 10-presentation
6 10-presentation
Remi Arnaud
 
States, state graphs and transition testing
States, state graphs and transition testingStates, state graphs and transition testing
States, state graphs and transition testing
ABHISHEK KUMAR
 
Potter’S Wheel
Potter’S WheelPotter’S Wheel
Potter’S Wheel
Dr Anjan Krishnamurthy
 
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 Action
cts2framework
 
Advanced web application architecture Way2Web
Advanced web application architecture Way2WebAdvanced web application architecture Way2Web
Advanced web application architecture Way2Web
Matthias Noback
 
The Clean Architecture
The Clean ArchitectureThe Clean Architecture
The Clean Architecture
Dmytro Turskyi
 
Liftweb
LiftwebLiftweb
Liftweb
Scalac
 
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 database
Son 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 7
mohammad hossein Jalili
 
Lecture 12
Lecture 12Lecture 12
Lecture 12
vishal choudhary
 
Hybrid Web Applications
Hybrid Web ApplicationsHybrid Web Applications
Hybrid Web Applications
James 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 Quarkus
Data Con LA
 
Java Web services
Java Web servicesJava Web services
Java Web services
Sujit 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 Programming
Speros Kokenes
 
Automate Software Change Estimation
Automate Software Change EstimationAutomate Software Change Estimation
Automate Software Change Estimation
Brenda 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
 
TY.BSc.IT Java QB U6
TY.BSc.IT Java QB U6TY.BSc.IT Java QB U6
TY.BSc.IT Java QB U6
Lokesh Singrol
 
6 10-presentation
6 10-presentation6 10-presentation
6 10-presentation
Remi Arnaud
 
States, state graphs and transition testing
States, state graphs and transition testingStates, state graphs and transition testing
States, state graphs and transition testing
ABHISHEK 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 Action
cts2framework
 
Advanced web application architecture Way2Web
Advanced web application architecture Way2WebAdvanced web application architecture Way2Web
Advanced web application architecture Way2Web
Matthias Noback
 
The Clean Architecture
The Clean ArchitectureThe Clean Architecture
The Clean Architecture
Dmytro Turskyi
 
Liftweb
LiftwebLiftweb
Liftweb
Scalac
 
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 database
Son 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 7
mohammad hossein Jalili
 
Hybrid Web Applications
Hybrid Web ApplicationsHybrid Web Applications
Hybrid Web Applications
James 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 Quarkus
Data Con LA
 
Java Web services
Java Web servicesJava Web services
Java Web services
Sujit 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 Programming
Speros Kokenes
 
Automate Software Change Estimation
Automate Software Change EstimationAutomate Software Change Estimation
Automate Software Change Estimation
Brenda 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
 

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
Ilia Idakiev
 
Enterprise State Management with NGRX/platform
Enterprise State Management with NGRX/platformEnterprise State Management with NGRX/platform
Enterprise State Management with NGRX/platform
Ilia Idakiev
 
Deep Dive into Zone.JS
Deep Dive into Zone.JSDeep Dive into Zone.JS
Deep Dive into Zone.JS
Ilia Idakiev
 
RxJS Schedulers - Controlling Time
RxJS Schedulers - Controlling TimeRxJS Schedulers - Controlling Time
RxJS Schedulers - Controlling Time
Ilia 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-html
Ilia 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 streams
Ilia Idakiev
 
Web Components Everywhere
Web Components EverywhereWeb Components Everywhere
Web Components Everywhere
Ilia Idakiev
 
Building Reusable Custom Elements With Angular
Building Reusable Custom Elements With AngularBuilding Reusable Custom Elements With Angular
Building Reusable Custom Elements With Angular
Ilia Idakiev
 
State management for enterprise angular applications
State management for enterprise angular applicationsState management for enterprise angular applications
State management for enterprise angular applications
Ilia 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 React
Ilia 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 angular
Ilia 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/platform
Ilia 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 Speed
Ilia 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 NodeJS
Ilia Idakiev
 
Introduction to Offline Progressive Web Applications
Introduction to Offline Progressive Web ApplicationsIntroduction to Offline Progressive Web Applications
Introduction to Offline Progressive Web Applications
Ilia Idakiev
 
Reflective injection using TypeScript
Reflective injection using TypeScriptReflective injection using TypeScript
Reflective injection using TypeScript
Ilia Idakiev
 
Zone.js
Zone.jsZone.js
Zone.js
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 Edit
Ilia Idakiev
 
Enterprise State Management with NGRX/platform
Enterprise State Management with NGRX/platformEnterprise State Management with NGRX/platform
Enterprise State Management with NGRX/platform
Ilia Idakiev
 
Deep Dive into Zone.JS
Deep Dive into Zone.JSDeep Dive into Zone.JS
Deep Dive into Zone.JS
Ilia Idakiev
 
RxJS Schedulers - Controlling Time
RxJS Schedulers - Controlling TimeRxJS Schedulers - Controlling Time
RxJS Schedulers - Controlling Time
Ilia 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-html
Ilia 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 streams
Ilia Idakiev
 
Web Components Everywhere
Web Components EverywhereWeb Components Everywhere
Web Components Everywhere
Ilia Idakiev
 
Building Reusable Custom Elements With Angular
Building Reusable Custom Elements With AngularBuilding Reusable Custom Elements With Angular
Building Reusable Custom Elements With Angular
Ilia Idakiev
 
State management for enterprise angular applications
State management for enterprise angular applicationsState management for enterprise angular applications
State management for enterprise angular applications
Ilia 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 React
Ilia 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 angular
Ilia 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/platform
Ilia 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 Speed
Ilia 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 NodeJS
Ilia Idakiev
 
Introduction to Offline Progressive Web Applications
Introduction to Offline Progressive Web ApplicationsIntroduction to Offline Progressive Web Applications
Introduction to Offline Progressive Web Applications
Ilia Idakiev
 
Reflective injection using TypeScript
Reflective injection using TypeScriptReflective injection using TypeScript
Reflective injection using TypeScript
Ilia Idakiev
 
Ad

Recently uploaded (20)

Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
Ad

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