SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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
 

Ähnlich wie Managing State in Single Page WebApps 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
 

Ähnlich wie Managing State in Single Page WebApps 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
 

Kürzlich hochgeladen

Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 

Kürzlich hochgeladen (20)

Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 

Managing State in Single Page WebApps 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

Hinweis der Redaktion

  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