SlideShare a Scribd company logo
1 of 34
Download to read offline
J O R G E L A I N F I E S TA
@jorgelainfiesta
Guatemala
India
Austria
HERACLITUS
PARMENIDES
vs
• Original object remains.
• Handle properties through set and get.
• Encourages object mutation.
• Computed properties, observers.
T H E E M B E R O B J E C T ( PA R M E N I D E S )
• Never modify an object.
• Create new objects all the time.
• Different solutions due constrains.
T H E H E R A C L I T U S WAY ( I M M U TA B I L I T Y )
• Tracking changes is easier.
• Simpler state management.
I M M U TA B L E D ATA F L O W S : W H Y ?
D E S I G N I N G
I M M U TA B L E D ATA F L O W S
I N E M B E R
J O R G E L A I N F I E S TA
• Simple form with text fields of
personal information.
• DDAU
B A S I C E X A M P L E
<label>Name:</label>
{{one-way-input (get person 'name') update=(action 'update' 'name')}}
<br>
<label>Surname:</label>
{{one-way-input (get person 'surname') update=(action 'update' 'surname')}}
<br>
<label>Email:</label>
{{one-way-input (get person 'email') update=(action 'update' 'email')}}
t e m p l a t e s / c o m p o n e n t s / u s e r - f o r m . h b s
import Ember from 'ember';
export default Ember.Component.extend({
actions: {
update(field, value) {
this.get('onUpdate')(field, value);
}
}
});
c o m p o n e n t s / u s e r - f o r m . j s
updateUser(field, value) {
let user = this.get('user');
set(user, field, value);
}
r e s p o n s i b l e p a r e n t
mutating object
updateUser(field, value) {
let user = {...this.get('user')};
set(user, field, value);
this.set('user', user);
}
r e s p o n s i b l e p a r e n t
not mutating
original object
updateUser(field, newData) {
let user = this.get('user');
this.set('user', { ...user, [field]: newData });
}
r e s p o n s i b l e p a r e n t
Immutability
C O N T R A C T S F O R C O M P O S I T I O N
Update the parent with the same
data type that they provided.
C O N T R A C T S F O R C O M P O S I T I O N
interface ImmutableComponentProps<E> {
value: E;
onUpdate: (updatedValue: E) => void
}
import Ember from 'ember';
export default Ember.Component.extend({
actions: {
update(field, value) {
this.get('onUpdate')({
[field]: value
});
}
}
});
c o m p o n e n t s / u s e r - f o r m . j s
updateUser(newData) {
let user = this.get('user');
this.set('user', { ...user, ...newData });
}
r e s p o n s i b l e p a r e n t
Immutability
{{user-form value=user onUpdate=(action 'updateUser')}}
r e s p o n s i b l e p a r e n t t e m p l a t e
W O R K I N G W I T H A R R AY S
W O R K I N G W I T H A R R AY S
★ map
★ reduce
★ filter
★ find
★ slice
• splice
• sort
• push
• Mutable array methods
in Ember
MutationsNo mutations
actions: {
addItem(newElement) {
let value = this.get('value');
this.get('onUpdate')([
...value,
newElement
]);
},
removeItem(index) {
let value = this.get('value');
this.get('onUpdate')([
...value.slice(0, index),
...value.slice(index + 1)
]);
}
}
c o m p o n e n t s / t o d o - l i s t . j s
updateList(newList) {
// Some treatment and processing?
this.set('list', newList);
}
r e s p o n s i b l e p a r e n t
{{todo-list value=list onUpdate=(action 'updateList')}}
r e s p o n s i b l e p a r e n t t e m p l a t e
C O M P U T E D P R O P E R T I E S
fullName: computed('user.{name,surname}', function() {
return `${this.get('user.name')} ${this.get('user.surname')}`;
})
r e s p o n s i b l e p a r e n t
fullName: computed('user', function() {
return `${this.get('user.name')} ${this.get('user.surname')}`;
})
r e s p o n s i b l e p a r e n t
N I C E F O R G L I M M E R
import Component, { tracked } from '@glimmer/component';
export default class ImmutabilityGlimmer extends Component {
@tracked user = {
name: 'Joe',
surname: 'Schreier'
};
@tracked('user')
get fullName() {
let { name, surname } = this.user;
return `${name} ${surname}`;
}
}
s o m e g l i m m e r c o m p o n e n t
updatePerson(personUpdate) {
let { user } = this;
this.user = {
...user,
...personUpdate
};
}
s o m e g l i m m e r c o m p o n e n t
<simple-form @user={{user}} @onUpdate={{updatePerson}} />
s o m e g l i m m e r c o m p o n e n t
T H E F U T U R E ?
K E E P I N T O U C H !
J O R G E L A I N F I E S TA
@jorgelainfiesta
DMs are open :)

More Related Content

What's hot

テストデータどうしてますか?
テストデータどうしてますか?テストデータどうしてますか?
テストデータどうしてますか?Yuki Shibazaki
 
Bindings: the zen of montage
Bindings: the zen of montageBindings: the zen of montage
Bindings: the zen of montageKris Kowal
 
Using Actions and Filters in WordPress to Make a Plugin Your Own
Using Actions and Filters in WordPress to Make a Plugin Your OwnUsing Actions and Filters in WordPress to Make a Plugin Your Own
Using Actions and Filters in WordPress to Make a Plugin Your OwnBrian Hogg
 
The next step, part 2
The next step, part 2The next step, part 2
The next step, part 2Pat Cavit
 
UI 모듈화로 워라밸 지키기
UI 모듈화로 워라밸 지키기UI 모듈화로 워라밸 지키기
UI 모듈화로 워라밸 지키기NAVER SHOPPING
 
Angular promises and http
Angular promises and httpAngular promises and http
Angular promises and httpAlexe Bogdan
 
The Ring programming language version 1.7 book - Part 25 of 196
The Ring programming language version 1.7 book - Part 25 of 196The Ring programming language version 1.7 book - Part 25 of 196
The Ring programming language version 1.7 book - Part 25 of 196Mahmoud Samir Fayed
 
Angular server-side communication
Angular server-side communicationAngular server-side communication
Angular server-side communicationAlexe Bogdan
 
Object-Oriented Javascript
Object-Oriented JavascriptObject-Oriented Javascript
Object-Oriented Javascriptkvangork
 
Sql server ___________session_20(ddl triggers)
Sql server  ___________session_20(ddl triggers)Sql server  ___________session_20(ddl triggers)
Sql server ___________session_20(ddl triggers)Ehtisham Ali
 

What's hot (19)

テストデータどうしてますか?
テストデータどうしてますか?テストデータどうしてますか?
テストデータどうしてますか?
 
Bindings: the zen of montage
Bindings: the zen of montageBindings: the zen of montage
Bindings: the zen of montage
 
Using Actions and Filters in WordPress to Make a Plugin Your Own
Using Actions and Filters in WordPress to Make a Plugin Your OwnUsing Actions and Filters in WordPress to Make a Plugin Your Own
Using Actions and Filters in WordPress to Make a Plugin Your Own
 
The next step, part 2
The next step, part 2The next step, part 2
The next step, part 2
 
UI 모듈화로 워라밸 지키기
UI 모듈화로 워라밸 지키기UI 모듈화로 워라밸 지키기
UI 모듈화로 워라밸 지키기
 
Formal methods
Formal methods Formal methods
Formal methods
 
linieaire regressie
linieaire regressielinieaire regressie
linieaire regressie
 
Road to react hooks
Road to react hooksRoad to react hooks
Road to react hooks
 
Ext oo
Ext ooExt oo
Ext oo
 
Functional programming with php7
Functional programming with php7Functional programming with php7
Functional programming with php7
 
Javascript
JavascriptJavascript
Javascript
 
6. CodeIgniter copy2
6. CodeIgniter copy26. CodeIgniter copy2
6. CodeIgniter copy2
 
Angular promises and http
Angular promises and httpAngular promises and http
Angular promises and http
 
Sencha Touch Intro
Sencha Touch IntroSencha Touch Intro
Sencha Touch Intro
 
The Ring programming language version 1.7 book - Part 25 of 196
The Ring programming language version 1.7 book - Part 25 of 196The Ring programming language version 1.7 book - Part 25 of 196
The Ring programming language version 1.7 book - Part 25 of 196
 
Angular server-side communication
Angular server-side communicationAngular server-side communication
Angular server-side communication
 
Object-Oriented Javascript
Object-Oriented JavascriptObject-Oriented Javascript
Object-Oriented Javascript
 
Jquery ajax & form
Jquery ajax & formJquery ajax & form
Jquery ajax & form
 
Sql server ___________session_20(ddl triggers)
Sql server  ___________session_20(ddl triggers)Sql server  ___________session_20(ddl triggers)
Sql server ___________session_20(ddl triggers)
 

Similar to Designing Immutability Data Flows in Ember

maJavaProjectFinalExam.classpathmaJavaProjectFinalExam.p.docx
maJavaProjectFinalExam.classpathmaJavaProjectFinalExam.p.docxmaJavaProjectFinalExam.classpathmaJavaProjectFinalExam.p.docx
maJavaProjectFinalExam.classpathmaJavaProjectFinalExam.p.docxinfantsuk
 
HELP IN JAVACreate a main method and use these input files to tes.pdf
HELP IN JAVACreate a main method and use these input files to tes.pdfHELP IN JAVACreate a main method and use these input files to tes.pdf
HELP IN JAVACreate a main method and use these input files to tes.pdffatoryoutlets
 
PLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdf
PLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdfPLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdf
PLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdfmallik3000
 
package employeeType.employee;public class Employee {   private .pdf
package employeeType.employee;public class Employee {   private .pdfpackage employeeType.employee;public class Employee {   private .pdf
package employeeType.employee;public class Employee {   private .pdfanwarsadath111
 
public class Person { private String name; private int age;.pdf
public class Person { private String name; private int age;.pdfpublic class Person { private String name; private int age;.pdf
public class Person { private String name; private int age;.pdfarjuncp10
 
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docxsrcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docxwhitneyleman54422
 
Logic Equations Resolver J Script
Logic Equations Resolver   J ScriptLogic Equations Resolver   J Script
Logic Equations Resolver J ScriptRoman Agaev
 
package employeeType.employee;public abstract class Employee {  .pdf
package employeeType.employee;public abstract class Employee {  .pdfpackage employeeType.employee;public abstract class Employee {  .pdf
package employeeType.employee;public abstract class Employee {  .pdfnipuns1983
 
Introduction to ECMAScript 2015
Introduction to ECMAScript 2015Introduction to ECMAScript 2015
Introduction to ECMAScript 2015Tomasz Dziuda
 
JShell: The Ultimate Missing Tool
JShell: The Ultimate Missing ToolJShell: The Ultimate Missing Tool
JShell: The Ultimate Missing ToolRahman USTA
 
JavaOne 2017 | JShell: The Ultimate Missing Tool
 JavaOne 2017 | JShell: The Ultimate Missing Tool JavaOne 2017 | JShell: The Ultimate Missing Tool
JavaOne 2017 | JShell: The Ultimate Missing ToolHakan Özler
 
@author public class Person{   String sname, .pdf
  @author   public class Person{   String sname, .pdf  @author   public class Person{   String sname, .pdf
@author public class Person{   String sname, .pdfaplolomedicalstoremr
 
Test du futur avec Spock
Test du futur avec SpockTest du futur avec Spock
Test du futur avec SpockCARA_Lyon
 
java compilerCompiler1.javajava compilerCompiler1.javaimport.docx
java compilerCompiler1.javajava compilerCompiler1.javaimport.docxjava compilerCompiler1.javajava compilerCompiler1.javaimport.docx
java compilerCompiler1.javajava compilerCompiler1.javaimport.docxpriestmanmable
 
PHPUnit でよりよくテストを書くために
PHPUnit でよりよくテストを書くためにPHPUnit でよりよくテストを書くために
PHPUnit でよりよくテストを書くためにYuya Takeyama
 
Code moi une RH! (PHP tour 2017)
Code moi une RH! (PHP tour 2017)Code moi une RH! (PHP tour 2017)
Code moi une RH! (PHP tour 2017)Arnaud Langlade
 
{{components deepDive=true}}
{{components deepDive=true}}{{components deepDive=true}}
{{components deepDive=true}}raytiley
 
import java.io.-WPS Office.docx
import java.io.-WPS Office.docximport java.io.-WPS Office.docx
import java.io.-WPS Office.docxKatecate1
 
Create a Code that will add an Add, Edi, and Delete button to the GU.pdf
Create a Code that will add an Add, Edi, and Delete button to the GU.pdfCreate a Code that will add an Add, Edi, and Delete button to the GU.pdf
Create a Code that will add an Add, Edi, and Delete button to the GU.pdflakshmijewellery
 

Similar to Designing Immutability Data Flows in Ember (20)

maJavaProjectFinalExam.classpathmaJavaProjectFinalExam.p.docx
maJavaProjectFinalExam.classpathmaJavaProjectFinalExam.p.docxmaJavaProjectFinalExam.classpathmaJavaProjectFinalExam.p.docx
maJavaProjectFinalExam.classpathmaJavaProjectFinalExam.p.docx
 
HELP IN JAVACreate a main method and use these input files to tes.pdf
HELP IN JAVACreate a main method and use these input files to tes.pdfHELP IN JAVACreate a main method and use these input files to tes.pdf
HELP IN JAVACreate a main method and use these input files to tes.pdf
 
PLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdf
PLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdfPLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdf
PLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdf
 
package employeeType.employee;public class Employee {   private .pdf
package employeeType.employee;public class Employee {   private .pdfpackage employeeType.employee;public class Employee {   private .pdf
package employeeType.employee;public class Employee {   private .pdf
 
public class Person { private String name; private int age;.pdf
public class Person { private String name; private int age;.pdfpublic class Person { private String name; private int age;.pdf
public class Person { private String name; private int age;.pdf
 
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docxsrcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
 
Logic Equations Resolver J Script
Logic Equations Resolver   J ScriptLogic Equations Resolver   J Script
Logic Equations Resolver J Script
 
Functional JS+ ES6.pptx
Functional JS+ ES6.pptxFunctional JS+ ES6.pptx
Functional JS+ ES6.pptx
 
package employeeType.employee;public abstract class Employee {  .pdf
package employeeType.employee;public abstract class Employee {  .pdfpackage employeeType.employee;public abstract class Employee {  .pdf
package employeeType.employee;public abstract class Employee {  .pdf
 
Introduction to ECMAScript 2015
Introduction to ECMAScript 2015Introduction to ECMAScript 2015
Introduction to ECMAScript 2015
 
JShell: The Ultimate Missing Tool
JShell: The Ultimate Missing ToolJShell: The Ultimate Missing Tool
JShell: The Ultimate Missing Tool
 
JavaOne 2017 | JShell: The Ultimate Missing Tool
 JavaOne 2017 | JShell: The Ultimate Missing Tool JavaOne 2017 | JShell: The Ultimate Missing Tool
JavaOne 2017 | JShell: The Ultimate Missing Tool
 
@author public class Person{   String sname, .pdf
  @author   public class Person{   String sname, .pdf  @author   public class Person{   String sname, .pdf
@author public class Person{   String sname, .pdf
 
Test du futur avec Spock
Test du futur avec SpockTest du futur avec Spock
Test du futur avec Spock
 
java compilerCompiler1.javajava compilerCompiler1.javaimport.docx
java compilerCompiler1.javajava compilerCompiler1.javaimport.docxjava compilerCompiler1.javajava compilerCompiler1.javaimport.docx
java compilerCompiler1.javajava compilerCompiler1.javaimport.docx
 
PHPUnit でよりよくテストを書くために
PHPUnit でよりよくテストを書くためにPHPUnit でよりよくテストを書くために
PHPUnit でよりよくテストを書くために
 
Code moi une RH! (PHP tour 2017)
Code moi une RH! (PHP tour 2017)Code moi une RH! (PHP tour 2017)
Code moi une RH! (PHP tour 2017)
 
{{components deepDive=true}}
{{components deepDive=true}}{{components deepDive=true}}
{{components deepDive=true}}
 
import java.io.-WPS Office.docx
import java.io.-WPS Office.docximport java.io.-WPS Office.docx
import java.io.-WPS Office.docx
 
Create a Code that will add an Add, Edi, and Delete button to the GU.pdf
Create a Code that will add an Add, Edi, and Delete button to the GU.pdfCreate a Code that will add an Add, Edi, and Delete button to the GU.pdf
Create a Code that will add an Add, Edi, and Delete button to the GU.pdf
 

Recently uploaded

GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 

Recently uploaded (20)

GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 

Designing Immutability Data Flows in Ember

  • 1. J O R G E L A I N F I E S TA @jorgelainfiesta
  • 4. • Original object remains. • Handle properties through set and get. • Encourages object mutation. • Computed properties, observers. T H E E M B E R O B J E C T ( PA R M E N I D E S )
  • 5. • Never modify an object. • Create new objects all the time. • Different solutions due constrains. T H E H E R A C L I T U S WAY ( I M M U TA B I L I T Y )
  • 6. • Tracking changes is easier. • Simpler state management. I M M U TA B L E D ATA F L O W S : W H Y ?
  • 7. D E S I G N I N G I M M U TA B L E D ATA F L O W S I N E M B E R J O R G E L A I N F I E S TA
  • 8. • Simple form with text fields of personal information. • DDAU B A S I C E X A M P L E
  • 9. <label>Name:</label> {{one-way-input (get person 'name') update=(action 'update' 'name')}} <br> <label>Surname:</label> {{one-way-input (get person 'surname') update=(action 'update' 'surname')}} <br> <label>Email:</label> {{one-way-input (get person 'email') update=(action 'update' 'email')}} t e m p l a t e s / c o m p o n e n t s / u s e r - f o r m . h b s
  • 10. import Ember from 'ember'; export default Ember.Component.extend({ actions: { update(field, value) { this.get('onUpdate')(field, value); } } }); c o m p o n e n t s / u s e r - f o r m . j s
  • 11. updateUser(field, value) { let user = this.get('user'); set(user, field, value); } r e s p o n s i b l e p a r e n t mutating object
  • 12. updateUser(field, value) { let user = {...this.get('user')}; set(user, field, value); this.set('user', user); } r e s p o n s i b l e p a r e n t not mutating original object
  • 13. updateUser(field, newData) { let user = this.get('user'); this.set('user', { ...user, [field]: newData }); } r e s p o n s i b l e p a r e n t Immutability
  • 14. C O N T R A C T S F O R C O M P O S I T I O N
  • 15. Update the parent with the same data type that they provided. C O N T R A C T S F O R C O M P O S I T I O N interface ImmutableComponentProps<E> { value: E; onUpdate: (updatedValue: E) => void }
  • 16. import Ember from 'ember'; export default Ember.Component.extend({ actions: { update(field, value) { this.get('onUpdate')({ [field]: value }); } } }); c o m p o n e n t s / u s e r - f o r m . j s
  • 17. updateUser(newData) { let user = this.get('user'); this.set('user', { ...user, ...newData }); } r e s p o n s i b l e p a r e n t Immutability
  • 18. {{user-form value=user onUpdate=(action 'updateUser')}} r e s p o n s i b l e p a r e n t t e m p l a t e
  • 19.
  • 20.
  • 21. W O R K I N G W I T H A R R AY S
  • 22. W O R K I N G W I T H A R R AY S ★ map ★ reduce ★ filter ★ find ★ slice • splice • sort • push • Mutable array methods in Ember MutationsNo mutations
  • 23. actions: { addItem(newElement) { let value = this.get('value'); this.get('onUpdate')([ ...value, newElement ]); }, removeItem(index) { let value = this.get('value'); this.get('onUpdate')([ ...value.slice(0, index), ...value.slice(index + 1) ]); } } c o m p o n e n t s / t o d o - l i s t . j s
  • 24. updateList(newList) { // Some treatment and processing? this.set('list', newList); } r e s p o n s i b l e p a r e n t
  • 25. {{todo-list value=list onUpdate=(action 'updateList')}} r e s p o n s i b l e p a r e n t t e m p l a t e
  • 26. C O M P U T E D P R O P E R T I E S
  • 27. fullName: computed('user.{name,surname}', function() { return `${this.get('user.name')} ${this.get('user.surname')}`; }) r e s p o n s i b l e p a r e n t
  • 28. fullName: computed('user', function() { return `${this.get('user.name')} ${this.get('user.surname')}`; }) r e s p o n s i b l e p a r e n t
  • 29. N I C E F O R G L I M M E R
  • 30. import Component, { tracked } from '@glimmer/component'; export default class ImmutabilityGlimmer extends Component { @tracked user = { name: 'Joe', surname: 'Schreier' }; @tracked('user') get fullName() { let { name, surname } = this.user; return `${name} ${surname}`; } } s o m e g l i m m e r c o m p o n e n t
  • 31. updatePerson(personUpdate) { let { user } = this; this.user = { ...user, ...personUpdate }; } s o m e g l i m m e r c o m p o n e n t
  • 32. <simple-form @user={{user}} @onUpdate={{updatePerson}} /> s o m e g l i m m e r c o m p o n e n t
  • 33. T H E F U T U R E ?
  • 34. K E E P I N T O U C H ! J O R G E L A I N F I E S TA @jorgelainfiesta DMs are open :)