SlideShare a Scribd company logo
IMMUTABLE DATA AND TYPESCRIPT
IN AN EMBER.JS APPLICATION
INTRO
Hi, I’m Bill, on the internet my name is… > PIXELHANDLER
JUST YESTERDAY THREE KITTENS SHOWED UP AT HOME
Two will be leaving very soon 
I like the kitten
at the top, #1
The options are:
1. Cool cuddly
2. Way relaxed
3. Super active
These are the
Tacos that I eat
on Tuesday:
The meats are:
1. Fish
2. Pork
3. Chicken
INTRO
 Warning: this topic is not found in any of the current
Ember.js cow paths; or among the “safety of the herd”
 Well, except for that part of… using a framework built with
great tooling and testing
 Walkthrough an approach to using immutable data and
static type analysis in an Ember.js app
 And, why you would not want to do the above
EXAMPLE APP - “ON BOARDING”
YOU KNOW ONLINE REGISTRATION
Immutable Data and TypeScript in an Ember.js Application
EXAMPLE APP: ON BOARDING
 This is not the use case, but rather a simple example that
everyone is familiar with
 The goal of the on-boarding app is to kick off a long
running task, e.g. register a user for a system.
 Perhaps the result would be to confirm email then set up
two-factor authentication.
 That is beside the point.
EXAMPLE APP: ON BOARDING
In addition to a practical review of code using ember-cli-
typescript and an approach to create immutable data
models (without Ember.Object), the on-boarding app has
some nice test examples using ember-native-dom-helpers,
and async/await (ember-maybe-import-regenerator),
mocking Fetch with Sinon.js, and a simple http-mock
endpoint so we don’t actually need a server.
INSPIRATION
OR MAYBE PERSPIRATION, NOT SURE YET
INSPIRATION: ELM LANG
 Elm Lang application architecture…
 Model- state of the app
 Update- change the state;
 View- present the state
 https://guide.elm-lang.org/architecture/
INSPIRATION: THE CLEAN CODER HIMSELF
 Uncle Bob said I should learn functional programming…
 “The bottom line is this. Functional programming is
important. You should learn it.” - Robert C. Martin (Uncle Bob)
 http://blog.cleancoder.com/uncle-bob/2017/07/11/PragmaticFunctionalProgramming.html
INSPIRATION: REACT
 Flux architecture …
 An application architecture for React utilizing
a unidirectional data flow
 https://github.com/facebook/flux/tree/master/examples
INSPIRATION: GLIMMER.JS
 To write maintainable, understandable components, we
recommend that you embrace the Immutable Pattern:
 Save component state as an "atom" in a tracked property
on the component.
 To change state, replace the root "atom" with a
new copy of the state.
 https://github.com/glimmerjs/glimmer-
website/blob/master/src/guides/tracked-properties.md#the-immutable-
pattern
MOTIVATIONS
USES CASES FROM A REAL WORLD SCENARIO
MOTIVATIONS: USE CASES FOR IMMUTABILITY
 Current project uses stateless
APIs and eventual
consistency
 Two users in the system, who
push changes back and forth
 Reload the app with current state of
user interface, e.g. which section of a
form the user is working on, which
fields are expanded, which fields are
checked, which fields are valid, which
button is enabled, etc. This is transient
state that can be derived (or reduced)
from values and configuration data for
a dynamic form interface.
MOTIVATIONS: USE CASES FOR IMMUTABILITY
 Aside from reload, push the
data between users and present
the same transient state, you
see what I see (based on the
data choices I or you make)
 Approach a solution (problem domain) by
modeling the user interface completely,
and use components that simply read from
their respective chuck of the model (state)
 Focus on data structures for a solution and
model the overall behavior vs. focus on
various isolated behaviors across many
components
MOTIVATIONS: USE CASES FOR IMMUTABILITY
 Create a solution that is
driven by configuration
that can meet various
custom requirements in a
multi-tenant system
 Use interfaces and static type
analysis to improve real time
feedback to the developer while
creating a solution
 Using types as well as interfaces
helps to improve documentation of
the problem/solution
MOTIVATIONS: USE CASES FOR IMMUTABILITY
 Close to real time
persistence of data changes
as users interact
 Since some changes affect other
properties in the state, use a consistent
way to model change sets
 Process changes when cloning a model
instance to generate the next
representation of that document for a
given screen in the web application
MOTIVATIONS: USE CASES FOR IMMUTABILITY
 Handle differing concerns
of the UI data model,
presentation and
persistence
 Presentation is derived from
persistent data, well data that will
eventually settle
 Instead of using bindings just set a
new model for the current screen
after processing data changes
generated by the user or another
user in the system
TYPESCRIPT: TESTING
Acceptance Test
 Used interface for mock Fetch
response
Service Unit test
 Used interfaces and types for items
under test as well as mocking
Fetch
Component Integration Test
 Used types for items under test
and spies in text context
Controller Unit Test
 Use model interface and type for
controller dependency, the model
CURRENTLY THE TS COMPILER IS PRETTY NOISEY
TYPESCRIPT: APPLICATION
Route
 Used interface for route protoype
and types for function params
Controller
 Used interface for controller
protoype and types for function
params, variable assignment
Service (Repo)
 Used interface for repository
method and types for function
params and variable assigment
Model
 Didn’t use Ember.Object, custom
interfaces, types to compose the
model of the user interface
Immutable Data and TypeScript in an Ember.js Application
SHOW ME THE MONEY, I MEAN THE CODE…
https://gitlab.com/pixelhandler/on-boarding/commits/master
The model uses a factory for nested models in the interface, hold on opening an editor
WRAP UP: TAKE-AWAYS
 There are some gotchas, but the benefits for the uses cases
I had were worth coding for those special cases:
- Component lifecycle create, destroy, etc.
- Create a new model without interrupting the user input
 There is much more code in the model layer of the app
WRAP UP: TAKE-AWAYS
 Less use of Ember practices which are based around
computing properties
 Don’t do this if your use cases do not demand it
 I’m curious why the components have to be destroyed
when the primitive properties of the model/state are the
same
ANY QUESTIONS
I STILL HAVE A BUNCH TOO 
Bill Heaton | @pixelhandler | https://pixelhandler.com
Immutable Data and TypeScript in an Ember.js Application
Immutable Data and TypeScript in an Ember.js Application
Immutable Data and TypeScript in an Ember.js Application
Immutable Data and TypeScript in an Ember.js Application
Immutable Data and TypeScript in an Ember.js Application
Immutable Data and TypeScript in an Ember.js Application

More Related Content

Similar to Immutable Data and TypeScript in an Ember.js Application (20)

BDD with SpecFlow and Selenium
BDD with SpecFlow and SeleniumBDD with SpecFlow and Selenium
BDD with SpecFlow and Selenium
Liraz Shay
 
Reusable Apps
Reusable AppsReusable Apps
Reusable Apps
DjangoCon2008
 
Design patterns
Design patternsDesign patterns
Design patterns
mudabbirwarsi
 
A report on mvc using the information
A report on mvc using the informationA report on mvc using the information
A report on mvc using the information
Toushik Paul
 
Testing Big in JavaScript
Testing Big in JavaScriptTesting Big in JavaScript
Testing Big in JavaScript
Robert DeLuca
 
Functional programming in TypeScript
Functional programming in TypeScriptFunctional programming in TypeScript
Functional programming in TypeScript
binDebug WorkSpace
 
Dive into Angular, part 5: Experience
Dive into Angular, part 5: ExperienceDive into Angular, part 5: Experience
Dive into Angular, part 5: Experience
Oleksii Prohonnyi
 
Building Maintainable Android Apps (DroidCon NYC 2014)
Building Maintainable Android Apps (DroidCon NYC 2014)Building Maintainable Android Apps (DroidCon NYC 2014)
Building Maintainable Android Apps (DroidCon NYC 2014)
Kevin Schultz
 
Code Quality Management iOS
Code Quality Management iOSCode Quality Management iOS
Code Quality Management iOS
Arpit Kulsreshtha
 
Building a full-stack app with Golang and Google Cloud Platform in one week
Building a full-stack app with Golang and Google Cloud Platform in one weekBuilding a full-stack app with Golang and Google Cloud Platform in one week
Building a full-stack app with Golang and Google Cloud Platform in one week
Dr. Felix Raab
 
Emberjs and ASP.NET
Emberjs and ASP.NETEmberjs and ASP.NET
Emberjs and ASP.NET
Mike Melusky
 
Everything You Need To Know About AngularJS
Everything You Need To Know About AngularJSEverything You Need To Know About AngularJS
Everything You Need To Know About AngularJS
Sina Mirhejazi
 
WebSphere Portlet Factory: Davalen’s Practical Advice from the Field
WebSphere Portlet Factory: Davalen’s Practical Advice from the Field WebSphere Portlet Factory: Davalen’s Practical Advice from the Field
WebSphere Portlet Factory: Davalen’s Practical Advice from the Field
Davalen LLC
 
Plug-in Architectures
Plug-in ArchitecturesPlug-in Architectures
Plug-in Architectures
elliando dias
 
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
Paul Jensen
 
Intro To Spring Python
Intro To Spring PythonIntro To Spring Python
Intro To Spring Python
gturnquist
 
Common design principles and design patterns in automation testing
Common design principles and design patterns in automation testingCommon design principles and design patterns in automation testing
Common design principles and design patterns in automation testing
KMS Technology
 
Spring boot
Spring bootSpring boot
Spring boot
NexThoughts Technologies
 
Rethinking Best Practices
Rethinking Best PracticesRethinking Best Practices
Rethinking Best Practices
floydophone
 
Automation testing
Automation testingAutomation testing
Automation testing
Tomy Rhymond
 
BDD with SpecFlow and Selenium
BDD with SpecFlow and SeleniumBDD with SpecFlow and Selenium
BDD with SpecFlow and Selenium
Liraz Shay
 
A report on mvc using the information
A report on mvc using the informationA report on mvc using the information
A report on mvc using the information
Toushik Paul
 
Testing Big in JavaScript
Testing Big in JavaScriptTesting Big in JavaScript
Testing Big in JavaScript
Robert DeLuca
 
Functional programming in TypeScript
Functional programming in TypeScriptFunctional programming in TypeScript
Functional programming in TypeScript
binDebug WorkSpace
 
Dive into Angular, part 5: Experience
Dive into Angular, part 5: ExperienceDive into Angular, part 5: Experience
Dive into Angular, part 5: Experience
Oleksii Prohonnyi
 
Building Maintainable Android Apps (DroidCon NYC 2014)
Building Maintainable Android Apps (DroidCon NYC 2014)Building Maintainable Android Apps (DroidCon NYC 2014)
Building Maintainable Android Apps (DroidCon NYC 2014)
Kevin Schultz
 
Building a full-stack app with Golang and Google Cloud Platform in one week
Building a full-stack app with Golang and Google Cloud Platform in one weekBuilding a full-stack app with Golang and Google Cloud Platform in one week
Building a full-stack app with Golang and Google Cloud Platform in one week
Dr. Felix Raab
 
Emberjs and ASP.NET
Emberjs and ASP.NETEmberjs and ASP.NET
Emberjs and ASP.NET
Mike Melusky
 
Everything You Need To Know About AngularJS
Everything You Need To Know About AngularJSEverything You Need To Know About AngularJS
Everything You Need To Know About AngularJS
Sina Mirhejazi
 
WebSphere Portlet Factory: Davalen’s Practical Advice from the Field
WebSphere Portlet Factory: Davalen’s Practical Advice from the Field WebSphere Portlet Factory: Davalen’s Practical Advice from the Field
WebSphere Portlet Factory: Davalen’s Practical Advice from the Field
Davalen LLC
 
Plug-in Architectures
Plug-in ArchitecturesPlug-in Architectures
Plug-in Architectures
elliando dias
 
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
Paul Jensen
 
Intro To Spring Python
Intro To Spring PythonIntro To Spring Python
Intro To Spring Python
gturnquist
 
Common design principles and design patterns in automation testing
Common design principles and design patterns in automation testingCommon design principles and design patterns in automation testing
Common design principles and design patterns in automation testing
KMS Technology
 
Rethinking Best Practices
Rethinking Best PracticesRethinking Best Practices
Rethinking Best Practices
floydophone
 
Automation testing
Automation testingAutomation testing
Automation testing
Tomy Rhymond
 

Recently uploaded (20)

Step by step guide to install Flutter and Dart
Step by step guide to install Flutter and DartStep by step guide to install Flutter and Dart
Step by step guide to install Flutter and Dart
S Pranav (Deepu)
 
Looking for a BIRT Report Alternative Here’s Why Helical Insight Stands Out.pdf
Looking for a BIRT Report Alternative Here’s Why Helical Insight Stands Out.pdfLooking for a BIRT Report Alternative Here’s Why Helical Insight Stands Out.pdf
Looking for a BIRT Report Alternative Here’s Why Helical Insight Stands Out.pdf
Varsha Nayak
 
Software Testing & it’s types (DevOps)
Software  Testing & it’s  types (DevOps)Software  Testing & it’s  types (DevOps)
Software Testing & it’s types (DevOps)
S Pranav (Deepu)
 
Migrating to Azure Cosmos DB the Right Way
Migrating to Azure Cosmos DB the Right WayMigrating to Azure Cosmos DB the Right Way
Migrating to Azure Cosmos DB the Right Way
Alexander (Alex) Komyagin
 
Transmission Media. (Computer Networks)
Transmission Media.  (Computer Networks)Transmission Media.  (Computer Networks)
Transmission Media. (Computer Networks)
S Pranav (Deepu)
 
SAP PM Module Level-IV Training Complete.ppt
SAP PM Module Level-IV Training Complete.pptSAP PM Module Level-IV Training Complete.ppt
SAP PM Module Level-IV Training Complete.ppt
MuhammadShaheryar36
 
Async-ronizing Success at Wix - Patterns for Seamless Microservices - Devoxx ...
Async-ronizing Success at Wix - Patterns for Seamless Microservices - Devoxx ...Async-ronizing Success at Wix - Patterns for Seamless Microservices - Devoxx ...
Async-ronizing Success at Wix - Patterns for Seamless Microservices - Devoxx ...
Natan Silnitsky
 
Automated Migration of ESRI Geodatabases Using XML Control Files and FME
Automated Migration of ESRI Geodatabases Using XML Control Files and FMEAutomated Migration of ESRI Geodatabases Using XML Control Files and FME
Automated Migration of ESRI Geodatabases Using XML Control Files and FME
Safe Software
 
Advanced Token Development - Decentralized Innovation
Advanced Token Development - Decentralized InnovationAdvanced Token Development - Decentralized Innovation
Advanced Token Development - Decentralized Innovation
arohisinghas720
 
What is data visualization and how data visualization tool can help.pdf
What is data visualization and how data visualization tool can help.pdfWhat is data visualization and how data visualization tool can help.pdf
What is data visualization and how data visualization tool can help.pdf
Varsha Nayak
 
Open Source Software Development Methods
Open Source Software Development MethodsOpen Source Software Development Methods
Open Source Software Development Methods
VICTOR MAESTRE RAMIREZ
 
OpenTelemetry 101 Cloud Native Barcelona
OpenTelemetry 101 Cloud Native BarcelonaOpenTelemetry 101 Cloud Native Barcelona
OpenTelemetry 101 Cloud Native Barcelona
Imma Valls Bernaus
 
DevOps for AI: running LLMs in production with Kubernetes and KubeFlow
DevOps for AI: running LLMs in production with Kubernetes and KubeFlowDevOps for AI: running LLMs in production with Kubernetes and KubeFlow
DevOps for AI: running LLMs in production with Kubernetes and KubeFlow
Aarno Aukia
 
Zoneranker’s Digital marketing solutions
Zoneranker’s Digital marketing solutionsZoneranker’s Digital marketing solutions
Zoneranker’s Digital marketing solutions
reenashriee
 
Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...
Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...
Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...
Alluxio, Inc.
 
Making significant Software Architecture decisions
Making significant Software Architecture decisionsMaking significant Software Architecture decisions
Making significant Software Architecture decisions
Bert Jan Schrijver
 
Plooma is a writing platform to plan, write, and shape books your way
Plooma is a writing platform to plan, write, and shape books your wayPlooma is a writing platform to plan, write, and shape books your way
Plooma is a writing platform to plan, write, and shape books your way
Plooma
 
IBM Rational Unified Process For Software Engineering - Introduction
IBM Rational Unified Process For Software Engineering - IntroductionIBM Rational Unified Process For Software Engineering - Introduction
IBM Rational Unified Process For Software Engineering - Introduction
Gaurav Sharma
 
UPDASP a project coordination unit ......
UPDASP a project coordination unit ......UPDASP a project coordination unit ......
UPDASP a project coordination unit ......
withrj1
 
Shell Skill Tree - LabEx Certification (LabEx)
Shell Skill Tree - LabEx Certification (LabEx)Shell Skill Tree - LabEx Certification (LabEx)
Shell Skill Tree - LabEx Certification (LabEx)
VICTOR MAESTRE RAMIREZ
 
Step by step guide to install Flutter and Dart
Step by step guide to install Flutter and DartStep by step guide to install Flutter and Dart
Step by step guide to install Flutter and Dart
S Pranav (Deepu)
 
Looking for a BIRT Report Alternative Here’s Why Helical Insight Stands Out.pdf
Looking for a BIRT Report Alternative Here’s Why Helical Insight Stands Out.pdfLooking for a BIRT Report Alternative Here’s Why Helical Insight Stands Out.pdf
Looking for a BIRT Report Alternative Here’s Why Helical Insight Stands Out.pdf
Varsha Nayak
 
Software Testing & it’s types (DevOps)
Software  Testing & it’s  types (DevOps)Software  Testing & it’s  types (DevOps)
Software Testing & it’s types (DevOps)
S Pranav (Deepu)
 
Transmission Media. (Computer Networks)
Transmission Media.  (Computer Networks)Transmission Media.  (Computer Networks)
Transmission Media. (Computer Networks)
S Pranav (Deepu)
 
SAP PM Module Level-IV Training Complete.ppt
SAP PM Module Level-IV Training Complete.pptSAP PM Module Level-IV Training Complete.ppt
SAP PM Module Level-IV Training Complete.ppt
MuhammadShaheryar36
 
Async-ronizing Success at Wix - Patterns for Seamless Microservices - Devoxx ...
Async-ronizing Success at Wix - Patterns for Seamless Microservices - Devoxx ...Async-ronizing Success at Wix - Patterns for Seamless Microservices - Devoxx ...
Async-ronizing Success at Wix - Patterns for Seamless Microservices - Devoxx ...
Natan Silnitsky
 
Automated Migration of ESRI Geodatabases Using XML Control Files and FME
Automated Migration of ESRI Geodatabases Using XML Control Files and FMEAutomated Migration of ESRI Geodatabases Using XML Control Files and FME
Automated Migration of ESRI Geodatabases Using XML Control Files and FME
Safe Software
 
Advanced Token Development - Decentralized Innovation
Advanced Token Development - Decentralized InnovationAdvanced Token Development - Decentralized Innovation
Advanced Token Development - Decentralized Innovation
arohisinghas720
 
What is data visualization and how data visualization tool can help.pdf
What is data visualization and how data visualization tool can help.pdfWhat is data visualization and how data visualization tool can help.pdf
What is data visualization and how data visualization tool can help.pdf
Varsha Nayak
 
Open Source Software Development Methods
Open Source Software Development MethodsOpen Source Software Development Methods
Open Source Software Development Methods
VICTOR MAESTRE RAMIREZ
 
OpenTelemetry 101 Cloud Native Barcelona
OpenTelemetry 101 Cloud Native BarcelonaOpenTelemetry 101 Cloud Native Barcelona
OpenTelemetry 101 Cloud Native Barcelona
Imma Valls Bernaus
 
DevOps for AI: running LLMs in production with Kubernetes and KubeFlow
DevOps for AI: running LLMs in production with Kubernetes and KubeFlowDevOps for AI: running LLMs in production with Kubernetes and KubeFlow
DevOps for AI: running LLMs in production with Kubernetes and KubeFlow
Aarno Aukia
 
Zoneranker’s Digital marketing solutions
Zoneranker’s Digital marketing solutionsZoneranker’s Digital marketing solutions
Zoneranker’s Digital marketing solutions
reenashriee
 
Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...
Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...
Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...
Alluxio, Inc.
 
Making significant Software Architecture decisions
Making significant Software Architecture decisionsMaking significant Software Architecture decisions
Making significant Software Architecture decisions
Bert Jan Schrijver
 
Plooma is a writing platform to plan, write, and shape books your way
Plooma is a writing platform to plan, write, and shape books your wayPlooma is a writing platform to plan, write, and shape books your way
Plooma is a writing platform to plan, write, and shape books your way
Plooma
 
IBM Rational Unified Process For Software Engineering - Introduction
IBM Rational Unified Process For Software Engineering - IntroductionIBM Rational Unified Process For Software Engineering - Introduction
IBM Rational Unified Process For Software Engineering - Introduction
Gaurav Sharma
 
UPDASP a project coordination unit ......
UPDASP a project coordination unit ......UPDASP a project coordination unit ......
UPDASP a project coordination unit ......
withrj1
 
Shell Skill Tree - LabEx Certification (LabEx)
Shell Skill Tree - LabEx Certification (LabEx)Shell Skill Tree - LabEx Certification (LabEx)
Shell Skill Tree - LabEx Certification (LabEx)
VICTOR MAESTRE RAMIREZ
 
Ad

Immutable Data and TypeScript in an Ember.js Application

  • 1. IMMUTABLE DATA AND TYPESCRIPT IN AN EMBER.JS APPLICATION
  • 2. INTRO Hi, I’m Bill, on the internet my name is… > PIXELHANDLER
  • 3. JUST YESTERDAY THREE KITTENS SHOWED UP AT HOME Two will be leaving very soon 
  • 4. I like the kitten at the top, #1 The options are: 1. Cool cuddly 2. Way relaxed 3. Super active
  • 5. These are the Tacos that I eat on Tuesday: The meats are: 1. Fish 2. Pork 3. Chicken
  • 6. INTRO  Warning: this topic is not found in any of the current Ember.js cow paths; or among the “safety of the herd”  Well, except for that part of… using a framework built with great tooling and testing  Walkthrough an approach to using immutable data and static type analysis in an Ember.js app  And, why you would not want to do the above
  • 7. EXAMPLE APP - “ON BOARDING” YOU KNOW ONLINE REGISTRATION
  • 9. EXAMPLE APP: ON BOARDING  This is not the use case, but rather a simple example that everyone is familiar with  The goal of the on-boarding app is to kick off a long running task, e.g. register a user for a system.  Perhaps the result would be to confirm email then set up two-factor authentication.  That is beside the point.
  • 10. EXAMPLE APP: ON BOARDING In addition to a practical review of code using ember-cli- typescript and an approach to create immutable data models (without Ember.Object), the on-boarding app has some nice test examples using ember-native-dom-helpers, and async/await (ember-maybe-import-regenerator), mocking Fetch with Sinon.js, and a simple http-mock endpoint so we don’t actually need a server.
  • 12. INSPIRATION: ELM LANG  Elm Lang application architecture…  Model- state of the app  Update- change the state;  View- present the state  https://guide.elm-lang.org/architecture/
  • 13. INSPIRATION: THE CLEAN CODER HIMSELF  Uncle Bob said I should learn functional programming…  “The bottom line is this. Functional programming is important. You should learn it.” - Robert C. Martin (Uncle Bob)  http://blog.cleancoder.com/uncle-bob/2017/07/11/PragmaticFunctionalProgramming.html
  • 14. INSPIRATION: REACT  Flux architecture …  An application architecture for React utilizing a unidirectional data flow  https://github.com/facebook/flux/tree/master/examples
  • 15. INSPIRATION: GLIMMER.JS  To write maintainable, understandable components, we recommend that you embrace the Immutable Pattern:  Save component state as an "atom" in a tracked property on the component.  To change state, replace the root "atom" with a new copy of the state.  https://github.com/glimmerjs/glimmer- website/blob/master/src/guides/tracked-properties.md#the-immutable- pattern
  • 16. MOTIVATIONS USES CASES FROM A REAL WORLD SCENARIO
  • 17. MOTIVATIONS: USE CASES FOR IMMUTABILITY  Current project uses stateless APIs and eventual consistency  Two users in the system, who push changes back and forth  Reload the app with current state of user interface, e.g. which section of a form the user is working on, which fields are expanded, which fields are checked, which fields are valid, which button is enabled, etc. This is transient state that can be derived (or reduced) from values and configuration data for a dynamic form interface.
  • 18. MOTIVATIONS: USE CASES FOR IMMUTABILITY  Aside from reload, push the data between users and present the same transient state, you see what I see (based on the data choices I or you make)  Approach a solution (problem domain) by modeling the user interface completely, and use components that simply read from their respective chuck of the model (state)  Focus on data structures for a solution and model the overall behavior vs. focus on various isolated behaviors across many components
  • 19. MOTIVATIONS: USE CASES FOR IMMUTABILITY  Create a solution that is driven by configuration that can meet various custom requirements in a multi-tenant system  Use interfaces and static type analysis to improve real time feedback to the developer while creating a solution  Using types as well as interfaces helps to improve documentation of the problem/solution
  • 20. MOTIVATIONS: USE CASES FOR IMMUTABILITY  Close to real time persistence of data changes as users interact  Since some changes affect other properties in the state, use a consistent way to model change sets  Process changes when cloning a model instance to generate the next representation of that document for a given screen in the web application
  • 21. MOTIVATIONS: USE CASES FOR IMMUTABILITY  Handle differing concerns of the UI data model, presentation and persistence  Presentation is derived from persistent data, well data that will eventually settle  Instead of using bindings just set a new model for the current screen after processing data changes generated by the user or another user in the system
  • 22. TYPESCRIPT: TESTING Acceptance Test  Used interface for mock Fetch response Service Unit test  Used interfaces and types for items under test as well as mocking Fetch Component Integration Test  Used types for items under test and spies in text context Controller Unit Test  Use model interface and type for controller dependency, the model
  • 23. CURRENTLY THE TS COMPILER IS PRETTY NOISEY
  • 24. TYPESCRIPT: APPLICATION Route  Used interface for route protoype and types for function params Controller  Used interface for controller protoype and types for function params, variable assignment Service (Repo)  Used interface for repository method and types for function params and variable assigment Model  Didn’t use Ember.Object, custom interfaces, types to compose the model of the user interface
  • 26. SHOW ME THE MONEY, I MEAN THE CODE… https://gitlab.com/pixelhandler/on-boarding/commits/master The model uses a factory for nested models in the interface, hold on opening an editor
  • 27. WRAP UP: TAKE-AWAYS  There are some gotchas, but the benefits for the uses cases I had were worth coding for those special cases: - Component lifecycle create, destroy, etc. - Create a new model without interrupting the user input  There is much more code in the model layer of the app
  • 28. WRAP UP: TAKE-AWAYS  Less use of Ember practices which are based around computing properties  Don’t do this if your use cases do not demand it  I’m curious why the components have to be destroyed when the primitive properties of the model/state are the same
  • 29. ANY QUESTIONS I STILL HAVE A BUNCH TOO  Bill Heaton | @pixelhandler | https://pixelhandler.com