SlideShare a Scribd company logo
1 of 24
Download to read offline
Building Realtime
              Singlepage Apps
                      @HenrikJoreteg
                      (hurray for Twitter)




Friday, May 6, 2011
The web is in
                             DIRECT
                      competition with native
                               apps


Friday, May 6, 2011
Stop supporting
                      crappy browsers.

                        Just STOP!

Friday, May 6, 2011
focus on providing
                         compelling
                         experiences
               (with the latest technologies)


Friday, May 6, 2011
Adoption is directly
                      related to how easy
                       it is to tinker with.


Friday, May 6, 2011
Socket.io is to realtime
                what jQuery is to AJAX



Friday, May 6, 2011
Quick look at
                       Socket.io


Friday, May 6, 2011
Server
                      var http = require('http'),  
                          io = require('socket.io');

                      server = http.createServer(function(req, res){
                       // your normal server code
                       res.writeHead(200, {'Content-Type': 'text/html'});
                       res.end('<h1>Hello world</h1>');
                      });
                      server.listen(80);
                       
                      // socket.io
                      var socket = io.listen(server);
                      socket.on('connection', function(client){
                        // new client is here!
                        client.on('message', function(){ … })
                        client.on('disconnect', function(){ … })
                      });




Friday, May 6, 2011
Client
                      <script src="http://{node_server_url}/socket.io/socket.io.js"></script>
                      <script>
                        var socket = new io.Socket({node_server_url});
                        socket.connect();
                        socket.on('connect', function(){ … })
                        socket.on('message', function(){ … })
                        socket.on('disconnect', function(){ … })
                      </script>




Friday, May 6, 2011
It’s all about state



Friday, May 6, 2011
Quick Look at
                       Backbone.js


Friday, May 6, 2011
Backbone gives you Observable
               Models & Collections
          var App = Backbone.Model.extend({
            initialize: function () {
               this.bind(‘change:myProperty’, _(this.writeIt).bind(this));
            },
            writeIt: function () {
               console.log(“my prop is: “ + this.get(‘myProperty’));
            }
          });

          app = new App();
          app.set({myProperty: true}); // outputs: “my prop is: true”




Friday, May 6, 2011
Views just listen to model changes
                var AppView = Backbone.Model.extend({
                  initialize: function () {
                     this.model.bind(‘change’, _(this.render).bind(this));
                  },
                  render: function () {
                     this.el.html(ich.app(this.model.toJSON()));
                     return this;
                  }
                });

                var app = new App(); // init our model
                var appView = new AppView({ model: app, el:
                document.body }); // init our view

                appView.render();
                app.set({myProperty: true}); // will re-render the whole app


Friday, May 6, 2011
Quick look at
                        Capsule


Friday, May 6, 2011
Backbone.js
                             +
                      model nesting
                             +
                       serialization
                             +
                      event bubbling
Friday, May 6, 2011
Models shared by Server + Client
           (function () {

               ... detect and set up environment for CommonJS or browser here

               // Main app model
               exports.AppModel = Capsule.Model.extend({
                 type: 'app',
                 initialize: function (spec) {
                   this.register();
                   this.addChildCollection('members', exports.Members);
                   this.addChildModel('activityLog', exports.ActivityLogPage);
                 }
               });

             // other models
             exports.Members = ...
           })();



Friday, May 6, 2011
Server-side
      socket.on('connection', function (client) {
        var app, sessionId;

          // this is split out so we have a reference to it
          function sendClientChanges(changes) { client.send(changes); }

          client.on('message', function(message){
            var model, collection;

              switch (message.event) {
                case 'session':
                   ...
                   // Here you'd fetch your user from DB based on sessionid
                   // you'd also get the corresponding app state that they should have access to.
                   // `require` your shared models file and inflate or instantiate your root app model
                   // Then grab whatever else you need and send the intial state to the client.
                   client.send({
                     event: 'initial',
                     app: app.xport()
                   });

                      // bind to the root `publish` events to send any changes to this client
                      app.bind('publish', sendClientChanges);
                      ...



Friday, May 6, 2011
Clientside
                      $(function () {
                        var app = window.app = new AppModel();
                        window.socket = new io.Socket();

                        // get and send our session cookie
                        socket.on('connect', function() {
                          socket.send({
                            event: 'session',
                            cookie: $.cookie('&!')
                          });
                        });

                        socket.on(‘message’, ...
                      });



Friday, May 6, 2011
Clientside cont...
                      socket.on('message', function (msg) {
                        switch (msg.event) {
                          case 'initial':
                            //import app state
                            app.mport(msg.app);
                            // init and render our root view
                            view = window.view = new AppView({
                              el: $('body'),
                              model: app
                            }).render();
                            break;
                          case 'change':
                            app.modelGetter(msg.id).set(msg.data);
                            break;

                            ... other cases for `add`, `remove` etc.
                        }
                      });


Friday, May 6, 2011
Friday, May 6, 2011
Friday, May 6, 2011
Friday, May 6, 2011
Challenges
                      • Partially shared state
                         Hint, sync everything, have your
                         view render what’s relevant
                      • Scaling
                      • Providing external APIs




Friday, May 6, 2011
Thank you!
                         Helpful Resources:
           me on twitter: @HenrikJoreteg (hit me up for early invite to &!)
           Backbone.js: http://documentcloud.github.com/backbone/
           Capsule.js: https://github.com/andyet/capsule
           App Testing: http://funcunit.com,
           http://mwbrooks.github.com/dominator.js/



Friday, May 6, 2011

More Related Content

What's hot

Practical AngularJS
Practical AngularJSPractical AngularJS
Practical AngularJSWei Ru
 
Dependency injection with koin
Dependency injection with koinDependency injection with koin
Dependency injection with koinSean Tsai
 
ChtiJUG - Introduction à Angular2
ChtiJUG - Introduction à Angular2ChtiJUG - Introduction à Angular2
ChtiJUG - Introduction à Angular2Demey Emmanuel
 
Technozaure - Angular2
Technozaure - Angular2Technozaure - Angular2
Technozaure - Angular2Demey Emmanuel
 
[FEConf Korea 2017]Angular 컴포넌트 대화법
[FEConf Korea 2017]Angular 컴포넌트 대화법[FEConf Korea 2017]Angular 컴포넌트 대화법
[FEConf Korea 2017]Angular 컴포넌트 대화법Jeado Ko
 
Learning Appcelerator® Alloy™
Learning Appcelerator® Alloy™Learning Appcelerator® Alloy™
Learning Appcelerator® Alloy™Ricardo Alcocer
 
React ES5 to ES6 | React ES5 vs ES6 | React Tutorial for Beginners | React on...
React ES5 to ES6 | React ES5 vs ES6 | React Tutorial for Beginners | React on...React ES5 to ES6 | React ES5 vs ES6 | React Tutorial for Beginners | React on...
React ES5 to ES6 | React ES5 vs ES6 | React Tutorial for Beginners | React on...Edureka!
 

What's hot (12)

Wicket 6
Wicket 6Wicket 6
Wicket 6
 
Practical AngularJS
Practical AngularJSPractical AngularJS
Practical AngularJS
 
AngularJs-training
AngularJs-trainingAngularJs-training
AngularJs-training
 
Dependency injection with koin
Dependency injection with koinDependency injection with koin
Dependency injection with koin
 
9.Spring DI_4
9.Spring DI_49.Spring DI_4
9.Spring DI_4
 
ChtiJUG - Introduction à Angular2
ChtiJUG - Introduction à Angular2ChtiJUG - Introduction à Angular2
ChtiJUG - Introduction à Angular2
 
Technozaure - Angular2
Technozaure - Angular2Technozaure - Angular2
Technozaure - Angular2
 
[FEConf Korea 2017]Angular 컴포넌트 대화법
[FEConf Korea 2017]Angular 컴포넌트 대화법[FEConf Korea 2017]Angular 컴포넌트 대화법
[FEConf Korea 2017]Angular 컴포넌트 대화법
 
Learning Appcelerator® Alloy™
Learning Appcelerator® Alloy™Learning Appcelerator® Alloy™
Learning Appcelerator® Alloy™
 
Angular js architecture (v1.4.8)
Angular js architecture (v1.4.8)Angular js architecture (v1.4.8)
Angular js architecture (v1.4.8)
 
Explaination of angular
Explaination of angularExplaination of angular
Explaination of angular
 
React ES5 to ES6 | React ES5 vs ES6 | React Tutorial for Beginners | React on...
React ES5 to ES6 | React ES5 vs ES6 | React Tutorial for Beginners | React on...React ES5 to ES6 | React ES5 vs ES6 | React Tutorial for Beginners | React on...
React ES5 to ES6 | React ES5 vs ES6 | React Tutorial for Beginners | React on...
 

Similar to Node conf - building realtime webapps

Adding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsAdding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsJeff Durta
 
Nashville Symfony Functional Testing
Nashville Symfony Functional TestingNashville Symfony Functional Testing
Nashville Symfony Functional TestingBrent Shaffer
 
Introducing Applitude: Simple Module Management
Introducing Applitude: Simple Module ManagementIntroducing Applitude: Simple Module Management
Introducing Applitude: Simple Module ManagementEric Hamilton
 
Magento Imagine eCommerce Conference - February 2011 - Unit Testing with Magento
Magento Imagine eCommerce Conference - February 2011 - Unit Testing with MagentoMagento Imagine eCommerce Conference - February 2011 - Unit Testing with Magento
Magento Imagine eCommerce Conference - February 2011 - Unit Testing with Magentovarien
 
Magento's Imagine eCommerce Conference 2011 - Unit Testing with Magento
Magento's Imagine eCommerce Conference 2011 - Unit Testing with MagentoMagento's Imagine eCommerce Conference 2011 - Unit Testing with Magento
Magento's Imagine eCommerce Conference 2011 - Unit Testing with MagentoMagentoImagine
 
比XML更好用的Java Annotation
比XML更好用的Java Annotation比XML更好用的Java Annotation
比XML更好用的Java Annotationjavatwo2011
 
Android Architecture Components
Android Architecture ComponentsAndroid Architecture Components
Android Architecture ComponentsBurhanuddinRashid
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...Fabio Franzini
 
Java EE 7: Boosting Productivity and Embracing HTML5
Java EE 7: Boosting Productivity and Embracing HTML5Java EE 7: Boosting Productivity and Embracing HTML5
Java EE 7: Boosting Productivity and Embracing HTML5Arun Gupta
 
Java EE 7 Platform: Boosting Productivity and Embracing HTML5 - Arun Gupta (R...
Java EE 7 Platform: Boosting Productivity and Embracing HTML5 - Arun Gupta (R...Java EE 7 Platform: Boosting Productivity and Embracing HTML5 - Arun Gupta (R...
Java EE 7 Platform: Boosting Productivity and Embracing HTML5 - Arun Gupta (R...jaxLondonConference
 
Jquery Plugin
Jquery PluginJquery Plugin
Jquery PluginRavi Mone
 
Real Time App with Node.js
Real Time App with Node.jsReal Time App with Node.js
Real Time App with Node.jsJxck Jxck
 
YUI3 Modules
YUI3 ModulesYUI3 Modules
YUI3 Modulesa_pipkin
 
Vaadin 7 by Joonas Lehtinen
Vaadin 7 by Joonas LehtinenVaadin 7 by Joonas Lehtinen
Vaadin 7 by Joonas LehtinenCodemotion
 
Building Isomorphic Apps (JSConf.Asia 2014)
Building Isomorphic Apps (JSConf.Asia 2014)Building Isomorphic Apps (JSConf.Asia 2014)
Building Isomorphic Apps (JSConf.Asia 2014)Spike Brehm
 
Helma / RingoJS – Vienna.js Minitalk
Helma / RingoJS – Vienna.js MinitalkHelma / RingoJS – Vienna.js Minitalk
Helma / RingoJS – Vienna.js MinitalkPhilipp Naderer
 
A gently introduction to AngularJS
A gently introduction to AngularJSA gently introduction to AngularJS
A gently introduction to AngularJSGregor Woiwode
 

Similar to Node conf - building realtime webapps (20)

Adding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsAdding a modern twist to legacy web applications
Adding a modern twist to legacy web applications
 
Nashville Symfony Functional Testing
Nashville Symfony Functional TestingNashville Symfony Functional Testing
Nashville Symfony Functional Testing
 
Introducing Applitude: Simple Module Management
Introducing Applitude: Simple Module ManagementIntroducing Applitude: Simple Module Management
Introducing Applitude: Simple Module Management
 
Magento Imagine eCommerce Conference - February 2011 - Unit Testing with Magento
Magento Imagine eCommerce Conference - February 2011 - Unit Testing with MagentoMagento Imagine eCommerce Conference - February 2011 - Unit Testing with Magento
Magento Imagine eCommerce Conference - February 2011 - Unit Testing with Magento
 
Magento's Imagine eCommerce Conference 2011 - Unit Testing with Magento
Magento's Imagine eCommerce Conference 2011 - Unit Testing with MagentoMagento's Imagine eCommerce Conference 2011 - Unit Testing with Magento
Magento's Imagine eCommerce Conference 2011 - Unit Testing with Magento
 
比XML更好用的Java Annotation
比XML更好用的Java Annotation比XML更好用的Java Annotation
比XML更好用的Java Annotation
 
Android Architecture Components
Android Architecture ComponentsAndroid Architecture Components
Android Architecture Components
 
Backbone js
Backbone jsBackbone js
Backbone js
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
 
Pushing the Web: Interesting things to Know
Pushing the Web: Interesting things to KnowPushing the Web: Interesting things to Know
Pushing the Web: Interesting things to Know
 
Java EE 7: Boosting Productivity and Embracing HTML5
Java EE 7: Boosting Productivity and Embracing HTML5Java EE 7: Boosting Productivity and Embracing HTML5
Java EE 7: Boosting Productivity and Embracing HTML5
 
Java EE 7 Platform: Boosting Productivity and Embracing HTML5 - Arun Gupta (R...
Java EE 7 Platform: Boosting Productivity and Embracing HTML5 - Arun Gupta (R...Java EE 7 Platform: Boosting Productivity and Embracing HTML5 - Arun Gupta (R...
Java EE 7 Platform: Boosting Productivity and Embracing HTML5 - Arun Gupta (R...
 
Jquery Plugin
Jquery PluginJquery Plugin
Jquery Plugin
 
Real Time App with Node.js
Real Time App with Node.jsReal Time App with Node.js
Real Time App with Node.js
 
YUI3 Modules
YUI3 ModulesYUI3 Modules
YUI3 Modules
 
Vaadin 7 by Joonas Lehtinen
Vaadin 7 by Joonas LehtinenVaadin 7 by Joonas Lehtinen
Vaadin 7 by Joonas Lehtinen
 
Web components
Web componentsWeb components
Web components
 
Building Isomorphic Apps (JSConf.Asia 2014)
Building Isomorphic Apps (JSConf.Asia 2014)Building Isomorphic Apps (JSConf.Asia 2014)
Building Isomorphic Apps (JSConf.Asia 2014)
 
Helma / RingoJS – Vienna.js Minitalk
Helma / RingoJS – Vienna.js MinitalkHelma / RingoJS – Vienna.js Minitalk
Helma / RingoJS – Vienna.js Minitalk
 
A gently introduction to AngularJS
A gently introduction to AngularJSA gently introduction to AngularJS
A gently introduction to AngularJS
 

Recently uploaded

Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
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
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
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
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 

Recently uploaded (20)

Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
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
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
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
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 

Node conf - building realtime webapps

  • 1. Building Realtime Singlepage Apps @HenrikJoreteg (hurray for Twitter) Friday, May 6, 2011
  • 2. The web is in DIRECT competition with native apps Friday, May 6, 2011
  • 3. Stop supporting crappy browsers. Just STOP! Friday, May 6, 2011
  • 4. focus on providing compelling experiences (with the latest technologies) Friday, May 6, 2011
  • 5. Adoption is directly related to how easy it is to tinker with. Friday, May 6, 2011
  • 6. Socket.io is to realtime what jQuery is to AJAX Friday, May 6, 2011
  • 7. Quick look at Socket.io Friday, May 6, 2011
  • 8. Server var http = require('http'),       io = require('socket.io'); server = http.createServer(function(req, res){  // your normal server code  res.writeHead(200, {'Content-Type': 'text/html'});  res.end('<h1>Hello world</h1>'); }); server.listen(80);   // socket.io var socket = io.listen(server); socket.on('connection', function(client){   // new client is here!   client.on('message', function(){ … })   client.on('disconnect', function(){ … }) }); Friday, May 6, 2011
  • 9. Client <script src="http://{node_server_url}/socket.io/socket.io.js"></script> <script>   var socket = new io.Socket({node_server_url});   socket.connect();   socket.on('connect', function(){ … })   socket.on('message', function(){ … })   socket.on('disconnect', function(){ … }) </script> Friday, May 6, 2011
  • 10. It’s all about state Friday, May 6, 2011
  • 11. Quick Look at Backbone.js Friday, May 6, 2011
  • 12. Backbone gives you Observable Models & Collections var App = Backbone.Model.extend({ initialize: function () { this.bind(‘change:myProperty’, _(this.writeIt).bind(this)); }, writeIt: function () { console.log(“my prop is: “ + this.get(‘myProperty’)); } }); app = new App(); app.set({myProperty: true}); // outputs: “my prop is: true” Friday, May 6, 2011
  • 13. Views just listen to model changes var AppView = Backbone.Model.extend({ initialize: function () { this.model.bind(‘change’, _(this.render).bind(this)); }, render: function () { this.el.html(ich.app(this.model.toJSON())); return this; } }); var app = new App(); // init our model var appView = new AppView({ model: app, el: document.body }); // init our view appView.render(); app.set({myProperty: true}); // will re-render the whole app Friday, May 6, 2011
  • 14. Quick look at Capsule Friday, May 6, 2011
  • 15. Backbone.js + model nesting + serialization + event bubbling Friday, May 6, 2011
  • 16. Models shared by Server + Client (function () { ... detect and set up environment for CommonJS or browser here // Main app model exports.AppModel = Capsule.Model.extend({ type: 'app', initialize: function (spec) { this.register(); this.addChildCollection('members', exports.Members); this.addChildModel('activityLog', exports.ActivityLogPage); } }); // other models exports.Members = ... })(); Friday, May 6, 2011
  • 17. Server-side socket.on('connection', function (client) { var app, sessionId; // this is split out so we have a reference to it function sendClientChanges(changes) { client.send(changes); } client.on('message', function(message){ var model, collection; switch (message.event) { case 'session': ... // Here you'd fetch your user from DB based on sessionid // you'd also get the corresponding app state that they should have access to. // `require` your shared models file and inflate or instantiate your root app model // Then grab whatever else you need and send the intial state to the client. client.send({ event: 'initial', app: app.xport() }); // bind to the root `publish` events to send any changes to this client app.bind('publish', sendClientChanges); ... Friday, May 6, 2011
  • 18. Clientside $(function () { var app = window.app = new AppModel(); window.socket = new io.Socket(); // get and send our session cookie socket.on('connect', function() { socket.send({ event: 'session', cookie: $.cookie('&!') }); }); socket.on(‘message’, ... }); Friday, May 6, 2011
  • 19. Clientside cont... socket.on('message', function (msg) { switch (msg.event) { case 'initial': //import app state app.mport(msg.app); // init and render our root view view = window.view = new AppView({ el: $('body'), model: app }).render(); break; case 'change': app.modelGetter(msg.id).set(msg.data); break; ... other cases for `add`, `remove` etc. } }); Friday, May 6, 2011
  • 23. Challenges • Partially shared state Hint, sync everything, have your view render what’s relevant • Scaling • Providing external APIs Friday, May 6, 2011
  • 24. Thank you! Helpful Resources: me on twitter: @HenrikJoreteg (hit me up for early invite to &!) Backbone.js: http://documentcloud.github.com/backbone/ Capsule.js: https://github.com/andyet/capsule App Testing: http://funcunit.com, http://mwbrooks.github.com/dominator.js/ Friday, May 6, 2011