SlideShare une entreprise Scribd logo
1  sur  24
The SAM Pattern
J.J. DUBRAY
xgen.io
@metapgmr
xgen.io
• Web/Mobile/IoT/ChatBots
• Architecture Services
• Platform and tools API API
Systems of Record
API API
Services
If you could only remember one thing
State 1
State 2
ActionThis is an approximation
If you could remember another thing
Assignment
is not equivalent to
Mutation
© 2016 xgen.io
Modern GUIs have become just a Node in a
Dynamic Distributed System
• your friends,
• players
• your watch
• IoT sensors
• …
Events and Callbacks
Composability
Encapsulation
Subscriptions
Separation of Concern
Data Consistency
from
to
Maintainability
…
Ingo Mayer et al (https://infoscience.epfl.ch/record/176887/files/DeprecatingObservers2012.pdf)© 2016 xgen.io
After some intense
research …
1. Framing the code we used to
write as a “class/component”
2. Adding a “reactive” change
detection mechanism to re-render
components automatically each
time their properties change
Leading Web Frameworks like
React and Angular came up with a
… component Model …
Functional Reactive
Programming: Elm/Redux
• Immutable data
• Observables
• Pure functions
• Static typing
• Unidirectional data flow
Source: http://www.codemag.com/article/1601071
http://guide.elm-lang.org/architecture/user_input/buttons.html
The problem lies in the coupling
between the View and the Model…
View Model
Model
View
Model
View
Source: Seth Davenport, ng2-redux, https://www.youtube.com/watch?v=s4xr2avwv3s&t=2489s
33% of the code in Adobe’s desktop applications
is devoted to event handling logic
50% of the bugs reported during a product cycle
exist in this code
Sean Parent , “A Possible Future of Software Development”, Adobe 2007
Introducing SAM
- State-Action-Model -
??
The SAM Pattern
View
Model
??
© 2016 xgen.io
The SAM Pattern
View
Model
V = f(M) Counter = Counter + 1Counter = Counter + 1
var p_counter = counter + 1
counter = p_counter
var p_counter = counter + 1
counter.accept(p_counter)
var p_counter = counter + 1
counter.accept(p_counter).then(learn)
1 Proposers
2 Acceptor(s) 3 Learners
© 2016 xgen.io
Dr. Leslie Lamport: TLA+
http://research.microsoft.com/en-us/um/people/lamport/pubs/state-machine.pdf
{
}
SAM is Unapologetically
Focused on Mutation
View
Model
Actions
V = f(props)
State next-action(Model)
1 Proposers
2 Acceptor(s)
next-action(Model)
3Learner(s)
© 2016 xgen.io
dispatch(event)
Unidirectional Data Flow / Single State Tree
Create Proposal
Modify Data
State Representation
SAM Pattern
next-action
React/Redux Angular2 – Two Way Databinding
Let’s look at some code
© Akveo 2016
Angular2
Component
Coupling the business
logic to a Web Framework
is an anti-pattern
events
Properties
Angular2
Unidirectional Data Flow
Single State Tree
Actions
events
Properties
Actions
State
Model
SAM / Angular2
Actions
Model
State
A new Application Architecture
- Services, APIs and Microservices -
SAM Isolates APIs
from the View
CUD
R
There is no need for
• an immutable model (Redux)
• declarative effects (Elm, ~Redux)
They create more problems than they solve Create Proposal
Modify Data
State Representation
SAM Pattern
next-action
SAM + SAM
API API API
Consistency
APIs
Services
Microservices
Systems of Record
Services
Model
ActionsState
View
Model
DispatcherState
View
Model
Actions
View
Activity
ActionAction
In Summary
• Programming model
• Centered on Mutation, not
immutability
• True Single State Tree, no
Sagas/Stateful components
• Focused on ”what’s allowed”, not
subscriptions
• View Components are 100%
decoupled from the application
business logic
• Functional UI/HTML (code
generation), not templates
• Architecture
• Can be implemented
with the framework of
your choice (React,
Angular)
• Side-effects friendly
• Wiring agnostic
• Truly Isomorphic
• Action “Hang back” /
Generic Cancellations
• 3rd party Actions
(OAuth)
Questions?
http://sam.js.org/
http://xgen.io
jdubray@xgen.io

Contenu connexe

Tendances

Lecture_3_k-mean-clustering.ppt
Lecture_3_k-mean-clustering.pptLecture_3_k-mean-clustering.ppt
Lecture_3_k-mean-clustering.pptSyedNahin1
 
パーセプトロン型学習規則
パーセプトロン型学習規則パーセプトロン型学習規則
パーセプトロン型学習規則Shuhei Sowa
 
クラシックな機械学習の入門 6. 最適化と学習アルゴリズム
クラシックな機械学習の入門  6. 最適化と学習アルゴリズムクラシックな機械学習の入門  6. 最適化と学習アルゴリズム
クラシックな機械学習の入門 6. 最適化と学習アルゴリズムHiroshi Nakagawa
 
マハラノビス距離を用いた異常値検知
マハラノビス距離を用いた異常値検知マハラノビス距離を用いた異常値検知
マハラノビス距離を用いた異常値検知Yuto Mori
 
Ocular pharmacology [autosaved]
Ocular pharmacology [autosaved]Ocular pharmacology [autosaved]
Ocular pharmacology [autosaved]Vinitkumar MJ
 
はじめてのパターン認識4章後編
はじめてのパターン認識4章後編はじめてのパターン認識4章後編
はじめてのパターン認識4章後編Tanaka Hidenori
 
Optical and Non-optical Methods of Measuring Axial Length of Eye
Optical and Non-optical Methods of Measuring Axial Length of EyeOptical and Non-optical Methods of Measuring Axial Length of Eye
Optical and Non-optical Methods of Measuring Axial Length of EyeRabindraAdhikary
 

Tendances (13)

Ocular therapeutics2
Ocular therapeutics2Ocular therapeutics2
Ocular therapeutics2
 
Astigmatism
AstigmatismAstigmatism
Astigmatism
 
Lecture_3_k-mean-clustering.ppt
Lecture_3_k-mean-clustering.pptLecture_3_k-mean-clustering.ppt
Lecture_3_k-mean-clustering.ppt
 
Exotropia
ExotropiaExotropia
Exotropia
 
パーセプトロン型学習規則
パーセプトロン型学習規則パーセプトロン型学習規則
パーセプトロン型学習規則
 
クラシックな機械学習の入門 6. 最適化と学習アルゴリズム
クラシックな機械学習の入門  6. 最適化と学習アルゴリズムクラシックな機械学習の入門  6. 最適化と学習アルゴリズム
クラシックな機械学習の入門 6. 最適化と学習アルゴリズム
 
Contact lens
Contact lensContact lens
Contact lens
 
マハラノビス距離を用いた異常値検知
マハラノビス距離を用いた異常値検知マハラノビス距離を用いた異常値検知
マハラノビス距離を用いた異常値検知
 
ddpg seminar
ddpg seminarddpg seminar
ddpg seminar
 
2019 Prescribing Eyeglasses in Children
2019 Prescribing Eyeglasses in Children2019 Prescribing Eyeglasses in Children
2019 Prescribing Eyeglasses in Children
 
Ocular pharmacology [autosaved]
Ocular pharmacology [autosaved]Ocular pharmacology [autosaved]
Ocular pharmacology [autosaved]
 
はじめてのパターン認識4章後編
はじめてのパターン認識4章後編はじめてのパターン認識4章後編
はじめてのパターン認識4章後編
 
Optical and Non-optical Methods of Measuring Axial Length of Eye
Optical and Non-optical Methods of Measuring Axial Length of EyeOptical and Non-optical Methods of Measuring Axial Length of Eye
Optical and Non-optical Methods of Measuring Axial Length of Eye
 

Similaire à An Introduction to the SAM Pattern

The SAM Pattern: a Distributed System View of Front-End Architectures
The SAM Pattern: a Distributed System View of Front-End ArchitecturesThe SAM Pattern: a Distributed System View of Front-End Architectures
The SAM Pattern: a Distributed System View of Front-End ArchitecturesJean-Jacques Dubray
 
Reactive Java Robotics and IoT 2016
Reactive Java Robotics and IoT 2016Reactive Java Robotics and IoT 2016
Reactive Java Robotics and IoT 2016ilievt
 
OORPT Dynamic Analysis
OORPT Dynamic AnalysisOORPT Dynamic Analysis
OORPT Dynamic Analysislienhard
 
Keynote at-icpc-2020
Keynote at-icpc-2020Keynote at-icpc-2020
Keynote at-icpc-2020Ralf Laemmel
 
NGRX Apps in Depth
NGRX Apps in DepthNGRX Apps in Depth
NGRX Apps in DepthTrayan Iliev
 
Reactive Java Robotics and IoT - IPT Presentation @ Voxxed Days 2016
Reactive Java Robotics and IoT - IPT Presentation @ Voxxed Days 2016Reactive Java Robotics and IoT - IPT Presentation @ Voxxed Days 2016
Reactive Java Robotics and IoT - IPT Presentation @ Voxxed Days 2016Trayan Iliev
 
Crafted Design - LJC World Tour Mash Up 2014
Crafted Design - LJC World Tour Mash Up 2014Crafted Design - LJC World Tour Mash Up 2014
Crafted Design - LJC World Tour Mash Up 2014Sandro Mancuso
 
Reactive Java Robotics IoT - jPrime 2016
Reactive Java Robotics IoT - jPrime 2016Reactive Java Robotics IoT - jPrime 2016
Reactive Java Robotics IoT - jPrime 2016Trayan Iliev
 
Lambda Architecture and open source technology stack for real time big data
Lambda Architecture and open source technology stack for real time big dataLambda Architecture and open source technology stack for real time big data
Lambda Architecture and open source technology stack for real time big dataTrieu Nguyen
 
LINQ 2 SQL Presentation To Palmchip And Trg, Technology Resource Group
LINQ 2 SQL Presentation To Palmchip  And Trg, Technology Resource GroupLINQ 2 SQL Presentation To Palmchip  And Trg, Technology Resource Group
LINQ 2 SQL Presentation To Palmchip And Trg, Technology Resource GroupShahzad
 
Microservices with Spring 5 Webflux - jProfessionals
Microservices  with Spring 5 Webflux - jProfessionalsMicroservices  with Spring 5 Webflux - jProfessionals
Microservices with Spring 5 Webflux - jProfessionalsTrayan Iliev
 
Making Machine Learning Easy with H2O and WebFlux
Making Machine Learning Easy with H2O and WebFluxMaking Machine Learning Easy with H2O and WebFlux
Making Machine Learning Easy with H2O and WebFluxTrayan Iliev
 
Building Reactive Real-time Data Pipeline
Building Reactive Real-time Data PipelineBuilding Reactive Real-time Data Pipeline
Building Reactive Real-time Data PipelineTrieu Nguyen
 
Azure Service Fabric and the Actor Model: when did we forget Object Orientation?
Azure Service Fabric and the Actor Model: when did we forget Object Orientation?Azure Service Fabric and the Actor Model: when did we forget Object Orientation?
Azure Service Fabric and the Actor Model: when did we forget Object Orientation?João Pedro Martins
 
Reactive web
Reactive webReactive web
Reactive webdega1999
 
Crafted Design - ITAKE 2014
Crafted Design - ITAKE 2014Crafted Design - ITAKE 2014
Crafted Design - ITAKE 2014Sandro Mancuso
 
Reactive Programming on Android - RxAndroid - RxJava
Reactive Programming on Android - RxAndroid - RxJavaReactive Programming on Android - RxAndroid - RxJava
Reactive Programming on Android - RxAndroid - RxJavaAli Muzaffar
 
Spring 5 Webflux - Advances in Java 2018
Spring 5 Webflux - Advances in Java 2018Spring 5 Webflux - Advances in Java 2018
Spring 5 Webflux - Advances in Java 2018Trayan Iliev
 
"Frameworks in 2015" Андрей Листочкин
"Frameworks in 2015" Андрей Листочкин"Frameworks in 2015" Андрей Листочкин
"Frameworks in 2015" Андрей ЛисточкинFwdays
 
Streaming Analytics and Internet of Things - Geesara Prathap
Streaming Analytics and Internet of Things - Geesara PrathapStreaming Analytics and Internet of Things - Geesara Prathap
Streaming Analytics and Internet of Things - Geesara PrathapWithTheBest
 

Similaire à An Introduction to the SAM Pattern (20)

The SAM Pattern: a Distributed System View of Front-End Architectures
The SAM Pattern: a Distributed System View of Front-End ArchitecturesThe SAM Pattern: a Distributed System View of Front-End Architectures
The SAM Pattern: a Distributed System View of Front-End Architectures
 
Reactive Java Robotics and IoT 2016
Reactive Java Robotics and IoT 2016Reactive Java Robotics and IoT 2016
Reactive Java Robotics and IoT 2016
 
OORPT Dynamic Analysis
OORPT Dynamic AnalysisOORPT Dynamic Analysis
OORPT Dynamic Analysis
 
Keynote at-icpc-2020
Keynote at-icpc-2020Keynote at-icpc-2020
Keynote at-icpc-2020
 
NGRX Apps in Depth
NGRX Apps in DepthNGRX Apps in Depth
NGRX Apps in Depth
 
Reactive Java Robotics and IoT - IPT Presentation @ Voxxed Days 2016
Reactive Java Robotics and IoT - IPT Presentation @ Voxxed Days 2016Reactive Java Robotics and IoT - IPT Presentation @ Voxxed Days 2016
Reactive Java Robotics and IoT - IPT Presentation @ Voxxed Days 2016
 
Crafted Design - LJC World Tour Mash Up 2014
Crafted Design - LJC World Tour Mash Up 2014Crafted Design - LJC World Tour Mash Up 2014
Crafted Design - LJC World Tour Mash Up 2014
 
Reactive Java Robotics IoT - jPrime 2016
Reactive Java Robotics IoT - jPrime 2016Reactive Java Robotics IoT - jPrime 2016
Reactive Java Robotics IoT - jPrime 2016
 
Lambda Architecture and open source technology stack for real time big data
Lambda Architecture and open source technology stack for real time big dataLambda Architecture and open source technology stack for real time big data
Lambda Architecture and open source technology stack for real time big data
 
LINQ 2 SQL Presentation To Palmchip And Trg, Technology Resource Group
LINQ 2 SQL Presentation To Palmchip  And Trg, Technology Resource GroupLINQ 2 SQL Presentation To Palmchip  And Trg, Technology Resource Group
LINQ 2 SQL Presentation To Palmchip And Trg, Technology Resource Group
 
Microservices with Spring 5 Webflux - jProfessionals
Microservices  with Spring 5 Webflux - jProfessionalsMicroservices  with Spring 5 Webflux - jProfessionals
Microservices with Spring 5 Webflux - jProfessionals
 
Making Machine Learning Easy with H2O and WebFlux
Making Machine Learning Easy with H2O and WebFluxMaking Machine Learning Easy with H2O and WebFlux
Making Machine Learning Easy with H2O and WebFlux
 
Building Reactive Real-time Data Pipeline
Building Reactive Real-time Data PipelineBuilding Reactive Real-time Data Pipeline
Building Reactive Real-time Data Pipeline
 
Azure Service Fabric and the Actor Model: when did we forget Object Orientation?
Azure Service Fabric and the Actor Model: when did we forget Object Orientation?Azure Service Fabric and the Actor Model: when did we forget Object Orientation?
Azure Service Fabric and the Actor Model: when did we forget Object Orientation?
 
Reactive web
Reactive webReactive web
Reactive web
 
Crafted Design - ITAKE 2014
Crafted Design - ITAKE 2014Crafted Design - ITAKE 2014
Crafted Design - ITAKE 2014
 
Reactive Programming on Android - RxAndroid - RxJava
Reactive Programming on Android - RxAndroid - RxJavaReactive Programming on Android - RxAndroid - RxJava
Reactive Programming on Android - RxAndroid - RxJava
 
Spring 5 Webflux - Advances in Java 2018
Spring 5 Webflux - Advances in Java 2018Spring 5 Webflux - Advances in Java 2018
Spring 5 Webflux - Advances in Java 2018
 
"Frameworks in 2015" Андрей Листочкин
"Frameworks in 2015" Андрей Листочкин"Frameworks in 2015" Андрей Листочкин
"Frameworks in 2015" Андрей Листочкин
 
Streaming Analytics and Internet of Things - Geesara Prathap
Streaming Analytics and Internet of Things - Geesara PrathapStreaming Analytics and Internet of Things - Geesara Prathap
Streaming Analytics and Internet of Things - Geesara Prathap
 

Dernier

FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
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
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 

Dernier (20)

FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
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
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 

An Introduction to the SAM Pattern

  • 1. The SAM Pattern J.J. DUBRAY xgen.io @metapgmr
  • 2. xgen.io • Web/Mobile/IoT/ChatBots • Architecture Services • Platform and tools API API Systems of Record API API Services
  • 3. If you could only remember one thing State 1 State 2 ActionThis is an approximation
  • 4. If you could remember another thing Assignment is not equivalent to Mutation
  • 5. © 2016 xgen.io Modern GUIs have become just a Node in a Dynamic Distributed System • your friends, • players • your watch • IoT sensors • …
  • 6. Events and Callbacks Composability Encapsulation Subscriptions Separation of Concern Data Consistency from to Maintainability … Ingo Mayer et al (https://infoscience.epfl.ch/record/176887/files/DeprecatingObservers2012.pdf)© 2016 xgen.io
  • 7. After some intense research … 1. Framing the code we used to write as a “class/component” 2. Adding a “reactive” change detection mechanism to re-render components automatically each time their properties change Leading Web Frameworks like React and Angular came up with a … component Model …
  • 8. Functional Reactive Programming: Elm/Redux • Immutable data • Observables • Pure functions • Static typing • Unidirectional data flow Source: http://www.codemag.com/article/1601071 http://guide.elm-lang.org/architecture/user_input/buttons.html
  • 9. The problem lies in the coupling between the View and the Model… View Model Model View Model View Source: Seth Davenport, ng2-redux, https://www.youtube.com/watch?v=s4xr2avwv3s&t=2489s
  • 10. 33% of the code in Adobe’s desktop applications is devoted to event handling logic 50% of the bugs reported during a product cycle exist in this code Sean Parent , “A Possible Future of Software Development”, Adobe 2007
  • 13. The SAM Pattern View Model V = f(M) Counter = Counter + 1Counter = Counter + 1 var p_counter = counter + 1 counter = p_counter var p_counter = counter + 1 counter.accept(p_counter) var p_counter = counter + 1 counter.accept(p_counter).then(learn) 1 Proposers 2 Acceptor(s) 3 Learners © 2016 xgen.io Dr. Leslie Lamport: TLA+ http://research.microsoft.com/en-us/um/people/lamport/pubs/state-machine.pdf { }
  • 14. SAM is Unapologetically Focused on Mutation View Model Actions V = f(props) State next-action(Model) 1 Proposers 2 Acceptor(s) next-action(Model) 3Learner(s) © 2016 xgen.io dispatch(event)
  • 15. Unidirectional Data Flow / Single State Tree Create Proposal Modify Data State Representation SAM Pattern next-action React/Redux Angular2 – Two Way Databinding
  • 16. Let’s look at some code © Akveo 2016
  • 17. Angular2 Component Coupling the business logic to a Web Framework is an anti-pattern events Properties
  • 18. Angular2 Unidirectional Data Flow Single State Tree Actions events Properties Actions State Model
  • 20. A new Application Architecture - Services, APIs and Microservices -
  • 21. SAM Isolates APIs from the View CUD R There is no need for • an immutable model (Redux) • declarative effects (Elm, ~Redux) They create more problems than they solve Create Proposal Modify Data State Representation SAM Pattern next-action
  • 22. SAM + SAM API API API Consistency APIs Services Microservices Systems of Record Services Model ActionsState View Model DispatcherState View Model Actions View Activity ActionAction
  • 23. In Summary • Programming model • Centered on Mutation, not immutability • True Single State Tree, no Sagas/Stateful components • Focused on ”what’s allowed”, not subscriptions • View Components are 100% decoupled from the application business logic • Functional UI/HTML (code generation), not templates • Architecture • Can be implemented with the framework of your choice (React, Angular) • Side-effects friendly • Wiring agnostic • Truly Isomorphic • Action “Hang back” / Generic Cancellations • 3rd party Actions (OAuth)

Notes de l'éditeur

  1. Graphical User Interfaces are part of a wide class of software, Reactive Applications, that responds to user input, network messages, and other events Reactive code is asynchronously triggered by event occurrences It is hard to trace and understand the control flow of the entire system