ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
Triforce your JavaScript with
Backbone, Promise and Singleton
My name is Alberto
@vrde
drinking beer && coding
Python/Semantic Web Services
http://lod-cloud.net/
Python on embedded devices
to control LED lights
Cofounder of Urlist
https://urli.st/
Architectural
overview
Tech Stack
Loads of Javascript
Python (Tornado)
GoLang
MongoDB
Problem
building a rich Web UI is hard
built¨Cin widgets
standards
client/server overlapping
built¨Cin widgets
standards
client/server overlapping
Solution
client UI / DOM¡ú
server JSON¡ú
The Server doesn't know
anything about the UI
it only exposes and
manipulates data
The Client handles user's
events and asks for
the data it needs
The Client is a collection of Widgets
Every widget is self¨Ccontained and is
responsible to ask for its data
Html5 bug
rendering your dashboard
1 GET to /api/profile/~
rendering your dashboard
1 GET to /api/profile/~
20 GETs to /api/list/
rendering your dashboard
1 GET to /api/profile/~
20 GETs to /api/list/
40 GETs to /api/user/
Pretty intense for the Server but
speeds up the development for
the Client
we've already optimized the client/server communication
Backbone
1
MV* library
(do the **** you want)
by Jeremy Ashkenas from DocumentCloud
easy to understand
almost easy to customize
Backbone
Backbone provides classes to represent:
Models
Views
Router
Singleton
2
Inspired by a post by SoundCloud
they call this pattern instance store
The Singleton Pattern
help us having one global
instance per ID
>>> a = new Backbone.Model({ id: 42 })
>>> b = new Backbone.Model({ id: 42 })
>>> a === b // true
IMO this should be the Backbone.Model default behaviour
Promise
3
¡°A Promise represents the
eventual value returned from the
single completion of an
operation.¡±
A Promise is an object
representation of an event
Example
>>> $.ajax({ success: log })
>>> var promise = $.ajax()
>>> promise.done(log)
log = function () { console.log(arguments) }
Example
>>> $.ajax({ success: log, error: log })
>>> var promise = $.ajax()
>>> promise.done(log)
>>> promise.fail(log)
log = function () { console.log(arguments) }
Example
>>> $.ajax({ success: [log, log],
error : log })
>>> var promise = $.ajax()
>>> promise.done(log)
>>> promise.fail(log)
>>> promise.done(log)
log = function () { console.log(arguments) }
all together now
Life cycle of a Visit
internal routing
{ hash: 'IOn' }
user visits
urli.st/IOn
Life cycle of a Visit
internal routing
{ hash: 'IOn' }
user visits
urli.st/IOn
Google
Analytics
l = new List(hash)
l.ajax()...
DOM Rendering
l = new List(hash)
l.ajax()...
Facebook
soon
l = new List(hash)
l.ajax()...
Mixpanel
l = new List(hash)
l.ajax()...
Life cycle of a Visit
internal routing
{ hash: 'IOn' }
user visits
urli.st/IOn
Google
Analytics
l = new List(hash)
l.ajax()...
DOM Rendering
l = new List(hash)
l.ajax()...
Facebook
soon
l = new List(hash)
l.ajax()...
Mixpanel
l = new List(hash)
l.ajax()...
List
instance
Life cycle of a Visit
internal routing
{ hash: 'IOn' }
user visits
urli.st/IOn
Google
Analytics
l = new List(hash)
l.ajax()...
DOM Rendering
l = new List(hash)
l.ajax()...
Facebook
soon
l = new List(hash)
l.ajax()...
Mixpanel
l = new List(hash)
l.ajax()...
List
instance Mongo
DB
Life cycle of a Visit
internal routing
{ hash: 'IOn' }
user visits
urli.st/IOn
Google
Analytics
l = new List(hash)
l.ajax()...
DOM Rendering
l = new List(hash)
l.ajax()...
Facebook
soon
l = new List(hash)
l.ajax()...
Mixpanel
l = new List(hash)
l.ajax()...
List
instance Mongo
DB
Sum up
delegating to the Client the
responsibility to ask data to the
Server speeds up our
development
combining Backbone with
Promises and Singletons keeps
the code clean and
easy to maintain
thanks
alberto@urli.st
resources of this presentation:
http://urli.st/IOn
PS: we are hiring
Html5 bug
introducing
hyperdrive
for (var i = 0; i < urlists.length; i++)
this.addWidget(urlists.at(i));
~3ms
step 1
override the
Backbone.sync
method to manage all the
fetch
step 2
use a Ticker object
to buffer all the GETs
~100 sloc

More Related Content

What's hot (20)

Phoenix + React¤Ç ÉçÄÚ¥·¥¹¥Æ¥à¤ò Ãܤ«¤Ë×÷¤Ã¤Æ¤ë
Phoenix + React¤Ç ÉçÄÚ¥·¥¹¥Æ¥à¤ò Ãܤ«¤Ë×÷¤Ã¤Æ¤ëPhoenix + React¤Ç ÉçÄÚ¥·¥¹¥Æ¥à¤ò Ãܤ«¤Ë×÷¤Ã¤Æ¤ë
Phoenix + React¤Ç ÉçÄÚ¥·¥¹¥Æ¥à¤ò Ãܤ«¤Ë×÷¤Ã¤Æ¤ë
Takahiro Kobaru
?
Rails web api ¿ª·¢
Rails web api ¿ª·¢Rails web api ¿ª·¢
Rails web api ¿ª·¢
shaokun
?
JavaScript Promises
JavaScript PromisesJavaScript Promises
JavaScript Promises
L&T Technology Services Limited
?
JavaScript Promises
JavaScript PromisesJavaScript Promises
JavaScript Promises
Tomasz Bak
?
More to RoC weibo
More to RoC weiboMore to RoC weibo
More to RoC weibo
shaokun
?
A Gentle Introduction to Event Loops
A Gentle Introduction to Event LoopsA Gentle Introduction to Event Loops
A Gentle Introduction to Event Loops
deepfountainconsulting
?
Unity and WebSockets
Unity and WebSocketsUnity and WebSockets
Unity and WebSockets
Josh Glover
?
Phpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friendsPhpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friends
Michael Peacock
?
Using the new WordPress REST API
Using the new WordPress REST APIUsing the new WordPress REST API
Using the new WordPress REST API
Caldera Labs
?
Avoiding callback hell in Node js using promises
Avoiding callback hell in Node js using promisesAvoiding callback hell in Node js using promises
Avoiding callback hell in Node js using promises
Ankit Agarwal
?
Iterators & generators: practical uses in memory management
Iterators & generators: practical uses in memory managementIterators & generators: practical uses in memory management
Iterators & generators: practical uses in memory management
Adrian Cardenas
?
The Beauty of Java Script
The Beauty of Java ScriptThe Beauty of Java Script
The Beauty of Java Script
Michael Girouard
?
Pragmatic Browser Automation with Geb - GIDS 2015
Pragmatic Browser Automation with Geb - GIDS 2015Pragmatic Browser Automation with Geb - GIDS 2015
Pragmatic Browser Automation with Geb - GIDS 2015
Naresha K
?
Promises, Promises
Promises, PromisesPromises, Promises
Promises, Promises
Domenic Denicola
?
Async Frontiers
Async FrontiersAsync Frontiers
Async Frontiers
Domenic Denicola
?
The Beauty Of Java Script V5a
The Beauty Of Java Script V5aThe Beauty Of Java Script V5a
The Beauty Of Java Script V5a
rajivmordani
?
ES6 is Nigh
ES6 is NighES6 is Nigh
ES6 is Nigh
Domenic Denicola
?
$q and Promises in AngularJS
$q and Promises in AngularJS $q and Promises in AngularJS
$q and Promises in AngularJS
a_sharif
?
Creating REST Applications with the Slim Micro-Framework by Vikram Vaswani
Creating REST Applications with the Slim Micro-Framework by Vikram VaswaniCreating REST Applications with the Slim Micro-Framework by Vikram Vaswani
Creating REST Applications with the Slim Micro-Framework by Vikram Vaswani
vvaswani
?
Angular&node js upload file
Angular&node js upload fileAngular&node js upload file
Angular&node js upload file
Hu Kenneth
?
Phoenix + React¤Ç ÉçÄÚ¥·¥¹¥Æ¥à¤ò Ãܤ«¤Ë×÷¤Ã¤Æ¤ë
Phoenix + React¤Ç ÉçÄÚ¥·¥¹¥Æ¥à¤ò Ãܤ«¤Ë×÷¤Ã¤Æ¤ëPhoenix + React¤Ç ÉçÄÚ¥·¥¹¥Æ¥à¤ò Ãܤ«¤Ë×÷¤Ã¤Æ¤ë
Phoenix + React¤Ç ÉçÄÚ¥·¥¹¥Æ¥à¤ò Ãܤ«¤Ë×÷¤Ã¤Æ¤ë
Takahiro Kobaru
?
Rails web api ¿ª·¢
Rails web api ¿ª·¢Rails web api ¿ª·¢
Rails web api ¿ª·¢
shaokun
?
JavaScript Promises
JavaScript PromisesJavaScript Promises
JavaScript Promises
Tomasz Bak
?
More to RoC weibo
More to RoC weiboMore to RoC weibo
More to RoC weibo
shaokun
?
Unity and WebSockets
Unity and WebSocketsUnity and WebSockets
Unity and WebSockets
Josh Glover
?
Phpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friendsPhpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friends
Michael Peacock
?
Using the new WordPress REST API
Using the new WordPress REST APIUsing the new WordPress REST API
Using the new WordPress REST API
Caldera Labs
?
Avoiding callback hell in Node js using promises
Avoiding callback hell in Node js using promisesAvoiding callback hell in Node js using promises
Avoiding callback hell in Node js using promises
Ankit Agarwal
?
Iterators & generators: practical uses in memory management
Iterators & generators: practical uses in memory managementIterators & generators: practical uses in memory management
Iterators & generators: practical uses in memory management
Adrian Cardenas
?
Pragmatic Browser Automation with Geb - GIDS 2015
Pragmatic Browser Automation with Geb - GIDS 2015Pragmatic Browser Automation with Geb - GIDS 2015
Pragmatic Browser Automation with Geb - GIDS 2015
Naresha K
?
The Beauty Of Java Script V5a
The Beauty Of Java Script V5aThe Beauty Of Java Script V5a
The Beauty Of Java Script V5a
rajivmordani
?
$q and Promises in AngularJS
$q and Promises in AngularJS $q and Promises in AngularJS
$q and Promises in AngularJS
a_sharif
?
Creating REST Applications with the Slim Micro-Framework by Vikram Vaswani
Creating REST Applications with the Slim Micro-Framework by Vikram VaswaniCreating REST Applications with the Slim Micro-Framework by Vikram Vaswani
Creating REST Applications with the Slim Micro-Framework by Vikram Vaswani
vvaswani
?
Angular&node js upload file
Angular&node js upload fileAngular&node js upload file
Angular&node js upload file
Hu Kenneth
?

Viewers also liked (15)

2009 Cancer Statistics
2009 Cancer Statistics2009 Cancer Statistics
2009 Cancer Statistics
cmurray
?
KaDouce AutoBio
KaDouce AutoBioKaDouce AutoBio
KaDouce AutoBio
Karine L
?
Tea
TeaTea
Tea
peerzada2009
?
Orarul profesorilor de la catedra psihologie
Orarul profesorilor de la catedra psihologieOrarul profesorilor de la catedra psihologie
Orarul profesorilor de la catedra psihologie
sergiu_sanduleac
?
Chapter 10-Holt causes of change
Chapter 10-Holt causes of changeChapter 10-Holt causes of change
Chapter 10-Holt causes of change
cmurray
?
Pycon4 Tastymess
Pycon4 TastymessPycon4 Tastymess
Pycon4 Tastymess
Alberto Granzotto
?
Eight Verses for Training the Mind: the Bodhisattva Ideal and the Bodhicitta ...
Eight Verses for Training the Mind: the Bodhisattva Ideal and the Bodhicitta ...Eight Verses for Training the Mind: the Bodhisattva Ideal and the Bodhicitta ...
Eight Verses for Training the Mind: the Bodhisattva Ideal and the Bodhicitta ...
manchesterbuddhistcentre
?
Wintertime
WintertimeWintertime
Wintertime
sergiu_sanduleac
?
Consciousness Wk 1 Summary & Wk 2
Consciousness Wk 1 Summary & Wk 2Consciousness Wk 1 Summary & Wk 2
Consciousness Wk 1 Summary & Wk 2
manchesterbuddhistcentre
?
Qpac
QpacQpac
Qpac
sergiu_sanduleac
?
Caro Candidato
Caro CandidatoCaro Candidato
Caro Candidato
Alberto Granzotto
?
Dog Flip Junior G.
Dog Flip Junior G.Dog Flip Junior G.
Dog Flip Junior G.
cali123
?
Letters Of Recommendation
Letters Of RecommendationLetters Of Recommendation
Letters Of Recommendation
MAD_Accountant
?
Las 10 claves tur¨ªsticas para afrontar en C¨®rdoba un escenario cambiante y ev...Las 10 claves tur¨ªsticas para afrontar en C¨®rdoba un escenario cambiante y ev...
Las 10 claves tur¨ªsticas para afrontar en C¨®rdoba un escenario cambiante y ev...
Jos¨¦ Antonio Garc¨ªa Su¨¢rez
?
La creatividad una estrategia para el desarrollo  urbano territorial en tiemp...La creatividad una estrategia para el desarrollo  urbano territorial en tiemp...
La creatividad una estrategia para el desarrollo urbano territorial en tiemp...
Jos¨¦ Antonio Garc¨ªa Su¨¢rez
?
2009 Cancer Statistics
2009 Cancer Statistics2009 Cancer Statistics
2009 Cancer Statistics
cmurray
?
KaDouce AutoBio
KaDouce AutoBioKaDouce AutoBio
KaDouce AutoBio
Karine L
?
Orarul profesorilor de la catedra psihologie
Orarul profesorilor de la catedra psihologieOrarul profesorilor de la catedra psihologie
Orarul profesorilor de la catedra psihologie
sergiu_sanduleac
?
Chapter 10-Holt causes of change
Chapter 10-Holt causes of changeChapter 10-Holt causes of change
Chapter 10-Holt causes of change
cmurray
?
Eight Verses for Training the Mind: the Bodhisattva Ideal and the Bodhicitta ...
Eight Verses for Training the Mind: the Bodhisattva Ideal and the Bodhicitta ...Eight Verses for Training the Mind: the Bodhisattva Ideal and the Bodhicitta ...
Eight Verses for Training the Mind: the Bodhisattva Ideal and the Bodhicitta ...
manchesterbuddhistcentre
?
Dog Flip Junior G.
Dog Flip Junior G.Dog Flip Junior G.
Dog Flip Junior G.
cali123
?
Letters Of Recommendation
Letters Of RecommendationLetters Of Recommendation
Letters Of Recommendation
MAD_Accountant
?
Las 10 claves tur¨ªsticas para afrontar en C¨®rdoba un escenario cambiante y ev...Las 10 claves tur¨ªsticas para afrontar en C¨®rdoba un escenario cambiante y ev...
Las 10 claves tur¨ªsticas para afrontar en C¨®rdoba un escenario cambiante y ev...
Jos¨¦ Antonio Garc¨ªa Su¨¢rez
?
La creatividad una estrategia para el desarrollo  urbano territorial en tiemp...La creatividad una estrategia para el desarrollo  urbano territorial en tiemp...
La creatividad una estrategia para el desarrollo urbano territorial en tiemp...
Jos¨¦ Antonio Garc¨ªa Su¨¢rez
?

Similar to Html5 bug (20)

Ç°¶Ë¸ÅÊö
Ç°¶Ë¸ÅÊöÇ°¶Ë¸ÅÊö
Ç°¶Ë¸ÅÊö
Ethan Zhang
?
TDC2017 | S?o Paulo - Trilha Java EE How we figured out we had a SRE team at ...
TDC2017 | S?o Paulo - Trilha Java EE How we figured out we had a SRE team at ...TDC2017 | S?o Paulo - Trilha Java EE How we figured out we had a SRE team at ...
TDC2017 | S?o Paulo - Trilha Java EE How we figured out we had a SRE team at ...
tdc-globalcode
?
Progressive web apps
Progressive web appsProgressive web apps
Progressive web apps
Fastly
?
NodeJS Tour
NodeJS TourNodeJS Tour
NodeJS Tour
Arunoda Susiripala
?
The Big Picture and How to Get Started
The Big Picture and How to Get StartedThe Big Picture and How to Get Started
The Big Picture and How to Get Started
guest1af57e
?
Cross Domain Web?Mashups with JQuery and Google App Engine
Cross Domain Web?Mashups with JQuery and Google App EngineCross Domain Web?Mashups with JQuery and Google App Engine
Cross Domain Web?Mashups with JQuery and Google App Engine
Andy McKay
?
Implementation of GUI Framework part3
Implementation of GUI Framework part3Implementation of GUI Framework part3
Implementation of GUI Framework part3
masahiroookubo
?
Socket applications
Socket applicationsSocket applications
Socket applications
Jo?o Moura
?
huhu
huhuhuhu
huhu
Dung Tr??ng
?
Construindo APIs de forma produtiva com Spring Boot, Spring Data e Spring MVC
Construindo APIs de forma produtiva com Spring Boot, Spring Data e Spring MVCConstruindo APIs de forma produtiva com Spring Boot, Spring Data e Spring MVC
Construindo APIs de forma produtiva com Spring Boot, Spring Data e Spring MVC
Emmanuel Neri
?
Developing node-mdb: a Node.js - based clone of SimpleDB
Developing node-mdb: a Node.js - based clone of SimpleDBDeveloping node-mdb: a Node.js - based clone of SimpleDB
Developing node-mdb: a Node.js - based clone of SimpleDB
Rob Tweed
?
Play Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and ScalaPlay Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and Scala
Yevgeniy Brikman
?
Intro to PSGI and Plack
Intro to PSGI and PlackIntro to PSGI and Plack
Intro to PSGI and Plack
Tatsuhiko Miyagawa
?
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
Mike Subelsky
?
Intoduction to Play Framework
Intoduction to Play FrameworkIntoduction to Play Framework
Intoduction to Play Framework
Knoldus Inc.
?
User Interface Patterns and Nuxeo
User Interface Patterns and NuxeoUser Interface Patterns and Nuxeo
User Interface Patterns and Nuxeo
anicewick
?
Silverlight 2 for Developers - TechEd New Zealand 2008
Silverlight 2 for Developers - TechEd New Zealand 2008Silverlight 2 for Developers - TechEd New Zealand 2008
Silverlight 2 for Developers - TechEd New Zealand 2008
Jonas Folles?
?
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)Boost Development With Java EE7 On EAP7 (Demitris Andreadis)
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)
Red Hat Developers
?
Play!ng with scala
Play!ng with scalaPlay!ng with scala
Play!ng with scala
Siarzh Miadzvedzeu
?
Universal JS Web Applications with React - Web Summer Camp 2017, Rovinj (Work...
Universal JS Web Applications with React - Web Summer Camp 2017, Rovinj (Work...Universal JS Web Applications with React - Web Summer Camp 2017, Rovinj (Work...
Universal JS Web Applications with React - Web Summer Camp 2017, Rovinj (Work...
Luciano Mammino
?
TDC2017 | S?o Paulo - Trilha Java EE How we figured out we had a SRE team at ...
TDC2017 | S?o Paulo - Trilha Java EE How we figured out we had a SRE team at ...TDC2017 | S?o Paulo - Trilha Java EE How we figured out we had a SRE team at ...
TDC2017 | S?o Paulo - Trilha Java EE How we figured out we had a SRE team at ...
tdc-globalcode
?
Progressive web apps
Progressive web appsProgressive web apps
Progressive web apps
Fastly
?
The Big Picture and How to Get Started
The Big Picture and How to Get StartedThe Big Picture and How to Get Started
The Big Picture and How to Get Started
guest1af57e
?
Cross Domain Web?Mashups with JQuery and Google App Engine
Cross Domain Web?Mashups with JQuery and Google App EngineCross Domain Web?Mashups with JQuery and Google App Engine
Cross Domain Web?Mashups with JQuery and Google App Engine
Andy McKay
?
Implementation of GUI Framework part3
Implementation of GUI Framework part3Implementation of GUI Framework part3
Implementation of GUI Framework part3
masahiroookubo
?
Socket applications
Socket applicationsSocket applications
Socket applications
Jo?o Moura
?
Construindo APIs de forma produtiva com Spring Boot, Spring Data e Spring MVC
Construindo APIs de forma produtiva com Spring Boot, Spring Data e Spring MVCConstruindo APIs de forma produtiva com Spring Boot, Spring Data e Spring MVC
Construindo APIs de forma produtiva com Spring Boot, Spring Data e Spring MVC
Emmanuel Neri
?
Developing node-mdb: a Node.js - based clone of SimpleDB
Developing node-mdb: a Node.js - based clone of SimpleDBDeveloping node-mdb: a Node.js - based clone of SimpleDB
Developing node-mdb: a Node.js - based clone of SimpleDB
Rob Tweed
?
Play Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and ScalaPlay Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and Scala
Yevgeniy Brikman
?
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
Mike Subelsky
?
Intoduction to Play Framework
Intoduction to Play FrameworkIntoduction to Play Framework
Intoduction to Play Framework
Knoldus Inc.
?
User Interface Patterns and Nuxeo
User Interface Patterns and NuxeoUser Interface Patterns and Nuxeo
User Interface Patterns and Nuxeo
anicewick
?
Silverlight 2 for Developers - TechEd New Zealand 2008
Silverlight 2 for Developers - TechEd New Zealand 2008Silverlight 2 for Developers - TechEd New Zealand 2008
Silverlight 2 for Developers - TechEd New Zealand 2008
Jonas Folles?
?
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)Boost Development With Java EE7 On EAP7 (Demitris Andreadis)
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)
Red Hat Developers
?
Universal JS Web Applications with React - Web Summer Camp 2017, Rovinj (Work...
Universal JS Web Applications with React - Web Summer Camp 2017, Rovinj (Work...Universal JS Web Applications with React - Web Summer Camp 2017, Rovinj (Work...
Universal JS Web Applications with React - Web Summer Camp 2017, Rovinj (Work...
Luciano Mammino
?

Html5 bug