SlideShare a Scribd company logo
1 of 28
Managing State in
  Single Page
     with Ember.js




                     16 Feb
Ember.js

• This is only to pique your interest
• Browser based MVC framework
• Builds on JQuery
• Beyond event driven abstractions
• Auto updating of DOM
Models

         Controllers
Models

         Controllers
User Template                 Task Template
mustache template             mustache template



    User View       Magic!        Task View




 Users Controller              Tasks Controller
selectedUser                  selectedUser




     User Model                   Task Model
name                          description
tasks
prettyName


                    Binding
User Template                         Task Template
mustache template                     mustache template

                              Magic
    User View       Magic!                Task View




 Users Controller                      Tasks Controller
selectedUser                          selectedUser




     User Model                           Task Model
name                                  description
tasks
prettyName


                    Binding
Ember Models
User = Ember.Object.extend({
    name: null,
    tasks: []
});

/* create two users */
bob = User.create({ name: "Bob" });
mark = User.create({ name: "Mark" });

bob.get("name"); //=> "Bob"
mark.get("name"); //=> "Mark"
Ember Models
User = Ember.Object.extend({
    name: null,
    tasks: []
});

/* create two users */
bob = User.create({ name: "Bob" });
mark = User.create({ name: "Mark" });

bob.get("name"); //=> "Bob"
mark.get("name"); //=> "Mark"
Users Controller
// A standard Ember Object
MyApp.usersController = Ember.Object.create({
    users: [],
    selectedUser: null,
});

MyApp.usersController.set("users", [bob, mark]);

// fake a <click> event
MyApp.usersController.set(“selectedUser”, bob);

MyApp.usersController.getPath("selectedUser.name");
//=> "Bob"
Users Controller
// A standard Ember Object
MyApp.usersController = Ember.Object.create({
    users: [],
    selectedUser: null,
});

MyApp.usersController.set("users", [bob, mark]);

// fake a <click> event
MyApp.usersController.set(“selectedUser”, bob);
                                         Magic
MyApp.usersController.getPath("selectedUser.name");
//=> "Bob"
Encapsulation

• Users View should only care about
  the Users Controller

• Tasks View should only care about
  the Tasks Controller
User Template       Task Template
mustache template   mustache template



    User View           Task View




 Users Controller    Tasks Controller
selectedUser        selectedUser




     User Model         Task Model
name                description
tasks
prettyName
Tasks Controllers

    // A standard Ember Object
MyApp.tasksController = Ember.Object.create({
    selectedUserBinding: 'MyApp.usersController.selectedUser'
});

MyApp.tasksController.getPath("selectedUser.name");
//=> "Mark" (or "Bob")
Tasks Controllers

                   Magic
    // A standard Ember Object
MyApp.tasksController = Ember.Object.create({
    selectedUserBinding: 'MyApp.usersController.selectedUser'
});

MyApp.tasksController.getPath("selectedUser.name");
//=> "Mark" (or "Bob")
Observers
MyApp.tasksController = Ember.Object.create({
      selectedUserBinding: 'MyApp.usersController.selectedUser',
      filterResults: function() {
        document.write("filter the results");
        // triggers a re-render
      }.observes('selectedUser')
});


// somehow the selected user is changed!
MyApp.usersController.set("selectedUser", mark);


MyApp.tasksController.getPath("selectedUser.name");
//=> "Mark" (or "Bob")
// side effect of "filter the results and re-render"
Observers
MyApp.tasksController = Ember.Object.create({
      selectedUserBinding: 'MyApp.usersController.selectedUser',
      filterResults: function() {
        document.write("filter the results");
        // triggers a re-render
      }.observes('selectedUser')
});


// somehow the selected user is changed!
MyApp.usersController.set("selectedUser", mark);


MyApp.tasksController.getPath("selectedUser.name");
//=> "Mark" (or "Bob")
// side effect of "filter the results and re-render"
Observers
MyApp.tasksController = Ember.Object.create({
      selectedUserBinding: 'MyApp.usersController.selectedUser',
      filterResults: function() {
        document.write("filter the results");
        // triggers a re-render
      }.observes('selectedUser')
});


// somehow the selected user is changed!
MyApp.usersController.set("selectedUser", mark);


MyApp.tasksController.getPath("selectedUser.name");
//=> "Mark" (or "Bob")
// side effect of "filter the results and re-render"
Computed Props
User = Ember.Object.extend({
    name: null,
    currentUserBinding: ‘MyApp.currentUser’,

      // computed property
      prettyName: function() {
         if(this == this.get(“currentUser”))
           return this.get(“name”) + " (me)";

         return this.get(“name”);
      }.property("name")
});

bob.get("prettyName"); //=> "Bob"
mark.get("prettyName"); //=> "Mark (me)"
Computed Props
User = Ember.Object.extend({
    name: null,
    currentUserBinding: ‘MyApp.currentUser’,

      // computed property
      prettyName: function() {
         if(this == this.get(“currentUser”))
           return this.get(“name”) + " (me)";

         return this.get(“name”);
      }.property("name")
});

bob.get("prettyName"); //=> "Bob"
mark.get("prettyName"); //=> "Mark (me)"
Computed Props
User = Ember.Object.extend({
    name: null,
    currentUserBinding: ‘MyApp.currentUser’,

      // computed property
      prettyName: function() {
         if(this == this.get(“currentUser”))
           return this.get(“name”) + " (me)";

         return this.get(“name”);
      }.property("name")
});

bob.get("prettyName"); //=> "Bob"
mark.get("prettyName"); //=> "Mark (me)"
Computed Props
User = Ember.Object.extend({
    name: null,
    currentUserBinding: ‘MyApp.currentUser’,

      // computed property
      prettyName: function() {
         if(this == this.get(“currentUser”))
           return this.get(“name”) + " (me)";

         return this.get(“name”);
      }.property("name")
});

bob.get("prettyName"); //=> "Bob"               MOAR Magic
mark.get("prettyName"); //=> "Mark (me)"
The Run Loop

• Pops a function on the queue
 •   (sync, actions, destroy, timers)


• Triggered each Browser Event Loop
• JavaScript FAST - DOM slow
The Run Loop

              Magic just
• Pops a function on the queue
 •             got real!
   (sync, actions, destroy, timers)


• Triggered each Browser Event Loop
• JavaScript FAST - DOM slow
What we just saw
• Data propagated through multiple
  objects

 • computed properties
 • observers
 • bindings
• Data updated in batch
What do I know?

• Very steep learning curve
 • (~4 weeks to get past novice)
• Modern Browsers Only
• Very, very powerful
Agile Bench
Planning tool for agile teams

More Related Content

What's hot

Mulberry: A Mobile App Development Toolkit
Mulberry: A Mobile App Development ToolkitMulberry: A Mobile App Development Toolkit
Mulberry: A Mobile App Development ToolkitRebecca Murphey
 
Dependency Management with RequireJS
Dependency Management with RequireJSDependency Management with RequireJS
Dependency Management with RequireJSAaronius
 
An introduction to Ember.js
An introduction to Ember.jsAn introduction to Ember.js
An introduction to Ember.jscodeofficer
 
Viking academy backbone.js
Viking academy  backbone.jsViking academy  backbone.js
Viking academy backbone.jsBert Wijnants
 
jQuery and_drupal
jQuery and_drupaljQuery and_drupal
jQuery and_drupalBlackCatWeb
 
A New Baseline for Front-End Devs
A New Baseline for Front-End DevsA New Baseline for Front-End Devs
A New Baseline for Front-End DevsRebecca Murphey
 
Week 4 - jQuery + Ajax
Week 4 - jQuery + AjaxWeek 4 - jQuery + Ajax
Week 4 - jQuery + Ajaxbaygross
 
AngularJS Directives
AngularJS DirectivesAngularJS Directives
AngularJS DirectivesEyal Vardi
 
Drupal Development (Part 2)
Drupal Development (Part 2)Drupal Development (Part 2)
Drupal Development (Part 2)Jeff Eaton
 
How Kris Writes Symfony Apps
How Kris Writes Symfony AppsHow Kris Writes Symfony Apps
How Kris Writes Symfony AppsKris Wallsmith
 
Drupal Javascript for developers
Drupal Javascript for developersDrupal Javascript for developers
Drupal Javascript for developersDream Production AG
 
Creating the interfaces of the future with the APIs of today
Creating the interfaces of the future with the APIs of todayCreating the interfaces of the future with the APIs of today
Creating the interfaces of the future with the APIs of todaygerbille
 
Introduction to backbone presentation
Introduction to backbone presentationIntroduction to backbone presentation
Introduction to backbone presentationBrian Hogg
 
Render API - Pavel Makhrinsky
Render API - Pavel MakhrinskyRender API - Pavel Makhrinsky
Render API - Pavel MakhrinskyDrupalCampDN
 
SproutCore and the Future of Web Apps
SproutCore and the Future of Web AppsSproutCore and the Future of Web Apps
SproutCore and the Future of Web AppsMike Subelsky
 
AngularJS Routing
AngularJS RoutingAngularJS Routing
AngularJS RoutingEyal Vardi
 

What's hot (20)

Mulberry: A Mobile App Development Toolkit
Mulberry: A Mobile App Development ToolkitMulberry: A Mobile App Development Toolkit
Mulberry: A Mobile App Development Toolkit
 
Dependency Management with RequireJS
Dependency Management with RequireJSDependency Management with RequireJS
Dependency Management with RequireJS
 
Intro to Ember.JS 2016
Intro to Ember.JS 2016Intro to Ember.JS 2016
Intro to Ember.JS 2016
 
DrupalCon jQuery
DrupalCon jQueryDrupalCon jQuery
DrupalCon jQuery
 
An introduction to Ember.js
An introduction to Ember.jsAn introduction to Ember.js
An introduction to Ember.js
 
Viking academy backbone.js
Viking academy  backbone.jsViking academy  backbone.js
Viking academy backbone.js
 
jQuery and_drupal
jQuery and_drupaljQuery and_drupal
jQuery and_drupal
 
A New Baseline for Front-End Devs
A New Baseline for Front-End DevsA New Baseline for Front-End Devs
A New Baseline for Front-End Devs
 
Week 4 - jQuery + Ajax
Week 4 - jQuery + AjaxWeek 4 - jQuery + Ajax
Week 4 - jQuery + Ajax
 
AngularJS Directives
AngularJS DirectivesAngularJS Directives
AngularJS Directives
 
Drupal Development (Part 2)
Drupal Development (Part 2)Drupal Development (Part 2)
Drupal Development (Part 2)
 
jQuery Best Practice
jQuery Best Practice jQuery Best Practice
jQuery Best Practice
 
How Kris Writes Symfony Apps
How Kris Writes Symfony AppsHow Kris Writes Symfony Apps
How Kris Writes Symfony Apps
 
Drupal Javascript for developers
Drupal Javascript for developersDrupal Javascript for developers
Drupal Javascript for developers
 
MVS: An angular MVC
MVS: An angular MVCMVS: An angular MVC
MVS: An angular MVC
 
Creating the interfaces of the future with the APIs of today
Creating the interfaces of the future with the APIs of todayCreating the interfaces of the future with the APIs of today
Creating the interfaces of the future with the APIs of today
 
Introduction to backbone presentation
Introduction to backbone presentationIntroduction to backbone presentation
Introduction to backbone presentation
 
Render API - Pavel Makhrinsky
Render API - Pavel MakhrinskyRender API - Pavel Makhrinsky
Render API - Pavel Makhrinsky
 
SproutCore and the Future of Web Apps
SproutCore and the Future of Web AppsSproutCore and the Future of Web Apps
SproutCore and the Future of Web Apps
 
AngularJS Routing
AngularJS RoutingAngularJS Routing
AngularJS Routing
 

Similar to Managing State in Single Page Apps with Ember.js

Ember.js - A JavaScript framework for creating ambitious web applications
Ember.js - A JavaScript framework for creating ambitious web applications  Ember.js - A JavaScript framework for creating ambitious web applications
Ember.js - A JavaScript framework for creating ambitious web applications Juliana Lucena
 
Java script+mvc+with+emberjs
Java script+mvc+with+emberjsJava script+mvc+with+emberjs
Java script+mvc+with+emberjsji guang
 
Building Ambitious Web Apps with Ember
Building Ambitious Web Apps with EmberBuilding Ambitious Web Apps with Ember
Building Ambitious Web Apps with Embergbabiars
 
MVC on the Server and on the Client: How to Integrate Spring MVC and Backbone...
MVC on the Server and on the Client: How to Integrate Spring MVC and Backbone...MVC on the Server and on the Client: How to Integrate Spring MVC and Backbone...
MVC on the Server and on the Client: How to Integrate Spring MVC and Backbone...jaxconf
 
QConSP 2015 - Dicas de Performance para Aplicações Web
QConSP 2015 - Dicas de Performance para Aplicações WebQConSP 2015 - Dicas de Performance para Aplicações Web
QConSP 2015 - Dicas de Performance para Aplicações WebFabio Akita
 
MVC on the server and on the client
MVC on the server and on the clientMVC on the server and on the client
MVC on the server and on the clientSebastiano Armeli
 
OSCON - ES6 metaprogramming unleashed
OSCON -  ES6 metaprogramming unleashedOSCON -  ES6 metaprogramming unleashed
OSCON - ES6 metaprogramming unleashedJavier Arias Losada
 
Javascript Frameworks for Joomla
Javascript Frameworks for JoomlaJavascript Frameworks for Joomla
Javascript Frameworks for JoomlaLuke Summerfield
 
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and JasmineSingle Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and JasminePaulo Ragonha
 
Object Oriented JavaScript
Object Oriented JavaScriptObject Oriented JavaScript
Object Oriented JavaScriptDonald Sipe
 
Rails 3: Dashing to the Finish
Rails 3: Dashing to the FinishRails 3: Dashing to the Finish
Rails 3: Dashing to the FinishYehuda Katz
 
An intro to Backbone.js
An intro to Backbone.jsAn intro to Backbone.js
An intro to Backbone.jstonydewan
 
React.js or why DOM finally makes sense
React.js or why DOM finally makes senseReact.js or why DOM finally makes sense
React.js or why DOM finally makes senseEldar Djafarov
 
Intro to emberjs
Intro to emberjsIntro to emberjs
Intro to emberjsMandy Pao
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overviewYehuda Katz
 
前端MVC 豆瓣说
前端MVC 豆瓣说前端MVC 豆瓣说
前端MVC 豆瓣说Ting Lv
 
Ember.js for Big Profit
Ember.js for Big ProfitEmber.js for Big Profit
Ember.js for Big ProfitCodeCore
 
Advanced javascript
Advanced javascriptAdvanced javascript
Advanced javascriptDoeun KOCH
 

Similar to Managing State in Single Page Apps with Ember.js (20)

Ember.js - A JavaScript framework for creating ambitious web applications
Ember.js - A JavaScript framework for creating ambitious web applications  Ember.js - A JavaScript framework for creating ambitious web applications
Ember.js - A JavaScript framework for creating ambitious web applications
 
Java script+mvc+with+emberjs
Java script+mvc+with+emberjsJava script+mvc+with+emberjs
Java script+mvc+with+emberjs
 
Building Ambitious Web Apps with Ember
Building Ambitious Web Apps with EmberBuilding Ambitious Web Apps with Ember
Building Ambitious Web Apps with Ember
 
MVC on the Server and on the Client: How to Integrate Spring MVC and Backbone...
MVC on the Server and on the Client: How to Integrate Spring MVC and Backbone...MVC on the Server and on the Client: How to Integrate Spring MVC and Backbone...
MVC on the Server and on the Client: How to Integrate Spring MVC and Backbone...
 
QConSP 2015 - Dicas de Performance para Aplicações Web
QConSP 2015 - Dicas de Performance para Aplicações WebQConSP 2015 - Dicas de Performance para Aplicações Web
QConSP 2015 - Dicas de Performance para Aplicações Web
 
MVC on the server and on the client
MVC on the server and on the clientMVC on the server and on the client
MVC on the server and on the client
 
OSCON - ES6 metaprogramming unleashed
OSCON -  ES6 metaprogramming unleashedOSCON -  ES6 metaprogramming unleashed
OSCON - ES6 metaprogramming unleashed
 
Javascript Frameworks for Joomla
Javascript Frameworks for JoomlaJavascript Frameworks for Joomla
Javascript Frameworks for Joomla
 
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and JasmineSingle Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
 
Backbone js
Backbone jsBackbone js
Backbone js
 
Object Oriented JavaScript
Object Oriented JavaScriptObject Oriented JavaScript
Object Oriented JavaScript
 
Rails 3: Dashing to the Finish
Rails 3: Dashing to the FinishRails 3: Dashing to the Finish
Rails 3: Dashing to the Finish
 
An intro to Backbone.js
An intro to Backbone.jsAn intro to Backbone.js
An intro to Backbone.js
 
React.js or why DOM finally makes sense
React.js or why DOM finally makes senseReact.js or why DOM finally makes sense
React.js or why DOM finally makes sense
 
Clean Javascript
Clean JavascriptClean Javascript
Clean Javascript
 
Intro to emberjs
Intro to emberjsIntro to emberjs
Intro to emberjs
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overview
 
前端MVC 豆瓣说
前端MVC 豆瓣说前端MVC 豆瓣说
前端MVC 豆瓣说
 
Ember.js for Big Profit
Ember.js for Big ProfitEmber.js for Big Profit
Ember.js for Big Profit
 
Advanced javascript
Advanced javascriptAdvanced javascript
Advanced javascript
 

Recently uploaded

2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 

Recently uploaded (20)

2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 

Managing State in Single Page Apps with Ember.js

  • 1. Managing State in Single Page with Ember.js 16 Feb
  • 2. Ember.js • This is only to pique your interest • Browser based MVC framework • Builds on JQuery • Beyond event driven abstractions • Auto updating of DOM
  • 3. Models Controllers
  • 4. Models Controllers
  • 5. User Template Task Template mustache template mustache template User View Magic! Task View Users Controller Tasks Controller selectedUser selectedUser User Model Task Model name description tasks prettyName Binding
  • 6. User Template Task Template mustache template mustache template Magic User View Magic! Task View Users Controller Tasks Controller selectedUser selectedUser User Model Task Model name description tasks prettyName Binding
  • 7. Ember Models User = Ember.Object.extend({ name: null, tasks: [] }); /* create two users */ bob = User.create({ name: "Bob" }); mark = User.create({ name: "Mark" }); bob.get("name"); //=> "Bob" mark.get("name"); //=> "Mark"
  • 8. Ember Models User = Ember.Object.extend({ name: null, tasks: [] }); /* create two users */ bob = User.create({ name: "Bob" }); mark = User.create({ name: "Mark" }); bob.get("name"); //=> "Bob" mark.get("name"); //=> "Mark"
  • 9. Users Controller // A standard Ember Object MyApp.usersController = Ember.Object.create({ users: [], selectedUser: null, }); MyApp.usersController.set("users", [bob, mark]); // fake a <click> event MyApp.usersController.set(“selectedUser”, bob); MyApp.usersController.getPath("selectedUser.name"); //=> "Bob"
  • 10. Users Controller // A standard Ember Object MyApp.usersController = Ember.Object.create({ users: [], selectedUser: null, }); MyApp.usersController.set("users", [bob, mark]); // fake a <click> event MyApp.usersController.set(“selectedUser”, bob); Magic MyApp.usersController.getPath("selectedUser.name"); //=> "Bob"
  • 11. Encapsulation • Users View should only care about the Users Controller • Tasks View should only care about the Tasks Controller
  • 12. User Template Task Template mustache template mustache template User View Task View Users Controller Tasks Controller selectedUser selectedUser User Model Task Model name description tasks prettyName
  • 13. Tasks Controllers // A standard Ember Object MyApp.tasksController = Ember.Object.create({ selectedUserBinding: 'MyApp.usersController.selectedUser' }); MyApp.tasksController.getPath("selectedUser.name"); //=> "Mark" (or "Bob")
  • 14. Tasks Controllers Magic // A standard Ember Object MyApp.tasksController = Ember.Object.create({ selectedUserBinding: 'MyApp.usersController.selectedUser' }); MyApp.tasksController.getPath("selectedUser.name"); //=> "Mark" (or "Bob")
  • 15. Observers MyApp.tasksController = Ember.Object.create({ selectedUserBinding: 'MyApp.usersController.selectedUser', filterResults: function() { document.write("filter the results"); // triggers a re-render }.observes('selectedUser') }); // somehow the selected user is changed! MyApp.usersController.set("selectedUser", mark); MyApp.tasksController.getPath("selectedUser.name"); //=> "Mark" (or "Bob") // side effect of "filter the results and re-render"
  • 16. Observers MyApp.tasksController = Ember.Object.create({ selectedUserBinding: 'MyApp.usersController.selectedUser', filterResults: function() { document.write("filter the results"); // triggers a re-render }.observes('selectedUser') }); // somehow the selected user is changed! MyApp.usersController.set("selectedUser", mark); MyApp.tasksController.getPath("selectedUser.name"); //=> "Mark" (or "Bob") // side effect of "filter the results and re-render"
  • 17. Observers MyApp.tasksController = Ember.Object.create({ selectedUserBinding: 'MyApp.usersController.selectedUser', filterResults: function() { document.write("filter the results"); // triggers a re-render }.observes('selectedUser') }); // somehow the selected user is changed! MyApp.usersController.set("selectedUser", mark); MyApp.tasksController.getPath("selectedUser.name"); //=> "Mark" (or "Bob") // side effect of "filter the results and re-render"
  • 18.
  • 19.
  • 20. Computed Props User = Ember.Object.extend({     name: null, currentUserBinding: ‘MyApp.currentUser’, // computed property prettyName: function() { if(this == this.get(“currentUser”)) return this.get(“name”) + " (me)"; return this.get(“name”); }.property("name") }); bob.get("prettyName"); //=> "Bob" mark.get("prettyName"); //=> "Mark (me)"
  • 21. Computed Props User = Ember.Object.extend({     name: null, currentUserBinding: ‘MyApp.currentUser’, // computed property prettyName: function() { if(this == this.get(“currentUser”)) return this.get(“name”) + " (me)"; return this.get(“name”); }.property("name") }); bob.get("prettyName"); //=> "Bob" mark.get("prettyName"); //=> "Mark (me)"
  • 22. Computed Props User = Ember.Object.extend({     name: null, currentUserBinding: ‘MyApp.currentUser’, // computed property prettyName: function() { if(this == this.get(“currentUser”)) return this.get(“name”) + " (me)"; return this.get(“name”); }.property("name") }); bob.get("prettyName"); //=> "Bob" mark.get("prettyName"); //=> "Mark (me)"
  • 23. Computed Props User = Ember.Object.extend({     name: null, currentUserBinding: ‘MyApp.currentUser’, // computed property prettyName: function() { if(this == this.get(“currentUser”)) return this.get(“name”) + " (me)"; return this.get(“name”); }.property("name") }); bob.get("prettyName"); //=> "Bob" MOAR Magic mark.get("prettyName"); //=> "Mark (me)"
  • 24. The Run Loop • Pops a function on the queue • (sync, actions, destroy, timers) • Triggered each Browser Event Loop • JavaScript FAST - DOM slow
  • 25. The Run Loop Magic just • Pops a function on the queue • got real! (sync, actions, destroy, timers) • Triggered each Browser Event Loop • JavaScript FAST - DOM slow
  • 26. What we just saw • Data propagated through multiple objects • computed properties • observers • bindings • Data updated in batch
  • 27. What do I know? • Very steep learning curve • (~4 weeks to get past novice) • Modern Browsers Only • Very, very powerful
  • 28. Agile Bench Planning tool for agile teams

Editor's Notes

  1. * you are web specialists, so I&amp;#x2019;m going to speak in code.\n* Using Ember to make Single Page WebApps like...\n* Gmail/Google Docs, iWork, Jetstar Hotels website\n\n
  2. This talk: Seriously, I only have 5 minutes!\n* technical, pique your interest\n\n* this talk is on the Ember Data Model - moving data around\n* Give you a lightning run-through of the Ember Object Model.\n\n* no time for talk about auto updating DOM (batchy)\n
  3. An example application\n1 - list of users - models and controllers\n2 - list of tasks - models and controllers\n3 - me! - modify a property\n\nWarning - a bit contrived. Not production quality code!\n
  4. An example application\n1 - list of users - models and controllers\n2 - list of tasks - models and controllers\n3 - me! - modify a property\n\nWarning - a bit contrived. Not production quality code!\n
  5. An example application\n1 - list of users - models and controllers\n2 - list of tasks - models and controllers\n3 - me! - modify a property\n\nWarning - a bit contrived. Not production quality code!\n
  6. An example application\n1 - list of users - models and controllers\n2 - list of tasks - models and controllers\n3 - me! - modify a property\n\nWarning - a bit contrived. Not production quality code!\n
  7. An example application\n1 - list of users - models and controllers\n2 - list of tasks - models and controllers\n3 - me! - modify a property\n\nWarning - a bit contrived. Not production quality code!\n
  8. An example application\n1 - list of users - models and controllers\n2 - list of tasks - models and controllers\n3 - me! - modify a property\n\nWarning - a bit contrived. Not production quality code!\n
  9. * focus on models and controllers\n* the arrows show data movement\n* create a user model and controller\n
  10. * focus on models and controllers\n* the arrows show data movement\n* create a user model and controller\n
  11. * focus on models and controllers\n* the arrows show data movement\n* create a user model and controller\n
  12. Simple User Model.\nHook up to view\n
  13. * long lived\n* created at app instantiation time\n* Somehow a user is selected\n* hook the Users Controller up to a view\n
  14. * long lived\n* created at app instantiation time\n* Somehow a user is selected\n* hook the Users Controller up to a view\n
  15. * long lived\n* created at app instantiation time\n* Somehow a user is selected\n* hook the Users Controller up to a view\n
  16. \n
  17. * the data we set in the controller (i.e. the selectedUser) is available to the view. We don&amp;#x2019;t want the Task View to use the user controllers data.\n* need to get the selectedUser over to the TasksController to update the list of tasks\n\n
  18. * there is now a selectedUser attribute on the controller object\n* the Tasks Controller is nicely encapsulated - doesn&amp;#x2019;t need to reach outside itself\n* this is the magic! Declaratively wire up data\n* The Task View only needs to reference the Tasks Controller\n* data just appears\n* refs are strings (lazily evaluated)\n
  19. * there is now a selectedUser attribute on the controller object\n* the Tasks Controller is nicely encapsulated - doesn&amp;#x2019;t need to reach outside itself\n* this is the magic! Declaratively wire up data\n* The Task View only needs to reference the Tasks Controller\n* data just appears\n* refs are strings (lazily evaluated)\n
  20. * observers notify you when a property changes so you can perform an action\n * kinda like an event, but not really\n
  21. * observers notify you when a property changes so you can perform an action\n * kinda like an event, but not really\n
  22. 1 - list of users\n2 - list of tasks\n3 - me!\n
  23. 1 - list of users\n2 - list of tasks\n3 - me!\n
  24. MyApp - Ember App Object\nprettyName - puts &amp;#x201C;(me)&amp;#x201D; on the current user\nAccess it as a property, not a function! It looks like data, not behaviour.\ngetPath can traverse an object graph!\nCould also have a setter computed property - full name &amp;#x201C;John Smith&amp;#x201D;\n
  25. MyApp - Ember App Object\nprettyName - puts &amp;#x201C;(me)&amp;#x201D; on the current user\nAccess it as a property, not a function! It looks like data, not behaviour.\ngetPath can traverse an object graph!\nCould also have a setter computed property - full name &amp;#x201C;John Smith&amp;#x201D;\n
  26. MyApp - Ember App Object\nprettyName - puts &amp;#x201C;(me)&amp;#x201D; on the current user\nAccess it as a property, not a function! It looks like data, not behaviour.\ngetPath can traverse an object graph!\nCould also have a setter computed property - full name &amp;#x201C;John Smith&amp;#x201D;\n
  27. MyApp - Ember App Object\nprettyName - puts &amp;#x201C;(me)&amp;#x201D; on the current user\nAccess it as a property, not a function! It looks like data, not behaviour.\ngetPath can traverse an object graph!\nCould also have a setter computed property - full name &amp;#x201C;John Smith&amp;#x201D;\n
  28. MyApp - Ember App Object\nprettyName - puts &amp;#x201C;(me)&amp;#x201D; on the current user\nAccess it as a property, not a function! It looks like data, not behaviour.\ngetPath can traverse an object graph!\nCould also have a setter computed property - full name &amp;#x201C;John Smith&amp;#x201D;\n
  29. MyApp - Ember App Object\nprettyName - puts &amp;#x201C;(me)&amp;#x201D; on the current user\nAccess it as a property, not a function! It looks like data, not behaviour.\ngetPath can traverse an object graph!\nCould also have a setter computed property - full name &amp;#x201C;John Smith&amp;#x201D;\n
  30. * OMG - super fast. Too fast for some of our users!\n* Computed Properties, Observers, Bindings are all managed within a run loop\n* Each set call is put on a queue (as a function) and popped off at the end of the run loop.\n* 4 queues - sync (bindings), actions (once off), destroy (remove objects), timers\n * we&amp;#x2019;ve seen 1000&amp;#x2019;s of items in the queues (normally 100s)\n* JavaScript is FAST - DOM is slow\n* getters, setters and creates are very powerful\n\n
  31. * OMG - super fast. Too fast for some of our users!\n* Computed Properties, Observers, Bindings are all managed within a run loop\n* Each set call is put on a queue (as a function) and popped off at the end of the run loop.\n* 4 queues - sync (bindings), actions (once off), destroy (remove objects), timers\n * we&amp;#x2019;ve seen 1000&amp;#x2019;s of items in the queues (normally 100s)\n* JavaScript is FAST - DOM is slow\n* getters, setters and creates are very powerful\n\n
  32. \n
  33. * Only for Modern Browsers - IE6 and 7 have slow JS runtimes - Chrome Frame\n* It blows your mind until you have an example to grasp onto. Doc isn&amp;#x2019;t great.\n* don&amp;#x2019;t try to combine this with CoffeeScript &amp; Jasmine at first - too much learning\n* very terse, modular code\n\n
  34. * please follow me on Twitter @markmansour @agilebench\n* 20 years on the intertubes. Pre-web baby! nntp and gopher FTW!\n