SlideShare a Scribd company logo
1 of 53
Download to read offline
Building Stateful Modules with Events and Promises
DOMManipulation
patrickCAMACHO
Beyond
Friday, June 14, 13
CrashlyticsforAndroid&iOS
Friday, June 14, 13
Friday, June 14, 13
Friday, June 14, 13
Friday, June 14, 13
Friday, June 14, 13
Railsto Backbone.
Friday, June 14, 13
Whatdidwehave?
Model
Backbone.Model
Backbone.Collection
Routing
Backbone.Router,
Backbone.History
Views
Backbone.Views
Events
Backbone.Events
MV* components
Friday, June 14, 13
What’smissing?
Friday, June 14, 13
TransitioningPagestoStates.
Friday, June 14, 13
Piecemeal.
App
State
Friday, June 14, 13
Piecemeal.
App
Router
State
Friday, June 14, 13
Piecemeal.
App
Router Directors
State
Friday, June 14, 13
Piecemeal.
App
Router Directors
State
Friday, June 14, 13
Addingamodal.
Friday, June 14, 13
Friday, June 14, 13
Neededbetterstructure.
• Builtonsingleflowand
states
• Modaldidn’tfitflow
• Backtothe
drawingboard
App
Router Directors
State
Friday, June 14, 13
Neededbetterstructure.
• Builtonsingleflowand
states
• Modaldidn’tfitflow
• Backtothe
drawingboard
App
Router Directors
State
Settings
Friday, June 14, 13
Thebirthofthe“module”.
• Entirelyindependentpiecesoffunctionality
• Itcouldaccepteventsandstart/stopitself
State
this.$('.settings').click(function(){
CLS.Components.Settings.trigger('start');
});
Settings
this.$('.overlay').click((function(){
this.trigger('stop');
}).bind(this));
Friday, June 14, 13
Asyncbehavior.
Friday, June 14, 13
Asyncbehaviorinstates.
• Fetchingdata,animations,etc
• Wanttoshutanythingdownwhenstopping
Settings
Server
(rendering)
Friday, June 14, 13
Promises.
• $.Promisesand$.Deferreds
• .done,.fail,.always
• .resolve,.reject
fetch1 = $.get('data.json');
fetch2 = $.get('data2.json');
fetch1.done(function(){ console.log(‘success!’); }
fetch2.always(function(){ console.log(‘complete!’); }
$.when(fetch1, fetch2).fail(function(){
console.log(‘fail!’);
});
Friday, June 14, 13
UsingwithComponents.
Settings.start = function() {
this.stopDeferred = $.Deferred();
fetch1 = $.get('data.json');
this.stopDeferred.done(fetch1.abort);
fetch2 = $.get('data2.json');
this.stopDeferred.done(fetch2.abort);
$.when(fetch1, fetch2).done(this.render.bind(this));
}
Settings.stop = function() {
this.stopDeferred.resolve();
}
Friday, June 14, 13
Goodintheshortrun.
• Onlyhadoneapplication
• Componentslived
forever
• Singletonshidthe
problems
Settings Alert Center
RealTime Analytics
Friday, June 14, 13
Multipleapplications.
Friday, June 14, 13
Distinctfunctionality.
Friday, June 14, 13
Distinctfunctionality.
Friday, June 14, 13
Multipleapplications.
• Lostcoreassumptionofapage-longapp
• Appsbegantolookmoreandmorelikemodules
Onboarding
Onboarding.start : function(){
if(this._isActive) return;
...
this._isActive = true;
}
Onboarding.stop : function(){
if(!this._isActive) return;
...
this._isActive = false;
}
Friday, June 14, 13
Multipleapplications.
Apps
Router Directors
State
Friday, June 14, 13
Persistentfunctionalty.
• Componentsneededtobestarted/stoppedbyappson
start/stop
• Notallshouldbestartedorstopped
• Backtoheavyconditionals
if(nextApp === 'onboard') {
CLS.Components.Settings.trigger('stop');
CLS.Components.AlertCenter.trigger('stop');
} else if(nextApp === 'logout') {
CLS.Components.Settings.trigger('stop');
CLS.Components.AlertCenter.trigger('stop');
CLS.Components.RealTime.trigger('stop');
} else if...
Friday, June 14, 13
Findingapattern.
Friday, June 14, 13
Sameproblem,differentlevels.
• Eventing
• Start
• Stop
• Dependencies
App
State State
Component Component Component
Friday, June 14, 13
Isolatingknowledge.
Friday, June 14, 13
Toomanydirectreferences.
• Don’tknowoutsideinformation
• Clearestinstoppingdependencies
if(nextApp === 'onboard') {
CLS.Components.Settings.trigger('stop');
CLS.Components.AlertCenter.trigger('stop');
} else if(nextApp === 'logout') {
CLS.Components.Settings.trigger('stop');
CLS.Components.AlertCenter.trigger('stop');
CLS.Components.RealTime.trigger('stop');
} else if...
Friday, June 14, 13
Eventingwitharguments.
Onboarding Dashboard
Dashboard.start = function() {
Onboarding.trigger('stop', this.dependencies);
}
Onboarding.stop = function(dependencies) {
if(dependencies == null) { dependencies = [] }
this.dependencies.forEach(function(dependencies){
if(dependencies.indexOf(dependency) < 0) {
dependency.trigger('stop', dependencies);
}
});
}
Friday, June 14, 13
• Wantedevents,butnottheknowledge
Stilltightlycoupled.
Dashboard.start = function() {
Onboarding.trigger('stop', this.dependencies);
LoggedOut.trigger('stop', this.dependencies);
}
Friday, June 14, 13
Simplifyfunctionality.
Friday, June 14, 13
Usingavent.
• Allofthesepiecesareusingevents
• Isolatethatfunctionalitytoasingleunit
Vent
Vent = function() {...}
Vent.prototype.on = function() {...}
Vent.prototype.one = function() {...}
Vent.prototype.off = function() {...}
Vent.prototype.trigger = function() {...}
Friday, June 14, 13
Sharingavent.
OnboardingDashboard Vent
Onboarding.start = function() {
this.vent.trigger('app:dashboard:stop', this.dependencies);
this.vent.trigger('app:loggedOut:stop', this.dependencies);
}
Friday, June 14, 13
Smartsubscriptions.
Dashboard.start = function(vent) {
this.vent.trigger('app:onBeforeStart', this.dependencies);
this.vent.one('app:onBeforeStart', this.stop.bind(this));
}
Onboarding.start = function(vent) {
this.vent.trigger('app:onBeforeStart', this.dependencies);
this.vent.one('app:onBeforeStart', this.stop.bind(this));
}
OnboardingDashboard Vent
Friday, June 14, 13
Sharinginformation.
Friday, June 14, 13
• Sharedatabetweenmodules
• Useventtoregisterresponsesandrequest
Synchronousdatareturns.
VentDashboard Settings
Friday, June 14, 13
Dashboard.start = function() {
this.currentApplication = ‘foo bar’
this.vent.setResponse(
'current_application',
(function(){ return this.currentApplication; }).bind(this);
);
}
Settings.start = function() {
app = this.vent.requestResponse('current_application');
}
Synchronousdatareturns.
Friday, June 14, 13
Tyingitalltogether.
Friday, June 14, 13
Modularizeallthethings!
• Isolatedfunctionality
• Start/stop
• Managingdependencies
• Eventing
• Asyncbehavior
Friday, June 14, 13
Modularizeallthethings!
Component
App
State
• Isolatedfunctionality
• Start/stop
• Managingdependencies
• Eventing
• Asyncbehavior
Friday, June 14, 13
Vent
Rethinkingtheflow.
Friday, June 14, 13
Vent
Rethinkingtheflow.
Router
Friday, June 14, 13
ComponentsVent
Rethinkingtheflow.
Apps
Router
Friday, June 14, 13
Vent
ComponentsVent
Rethinkingtheflow.
Apps
Router
States
Friday, June 14, 13
Vent
Vent
ComponentsVent
Rethinkingtheflow.
Apps
Router
States
States
Friday, June 14, 13
Makingityours
• Managecomplexityandscale
• Isolatefunctionalityintomodules
• Managedependencies
• Allowmodulestocommunicatethroughavent
Friday, June 14, 13
YOUpatrickCAMACHO
Thank
try.crashlytics.com/jobs
Friday, June 14, 13

More Related Content

What's hot

jQuery Conference San Diego 2014 - Web Performance
jQuery Conference San Diego 2014 - Web PerformancejQuery Conference San Diego 2014 - Web Performance
jQuery Conference San Diego 2014 - Web Performance
dmethvin
 
Javascript done right - Open Web Camp III
Javascript done right - Open Web Camp IIIJavascript done right - Open Web Camp III
Javascript done right - Open Web Camp III
Dirk Ginader
 
Djangoアプリのデプロイに関するプラクティス / Deploy django application
Djangoアプリのデプロイに関するプラクティス / Deploy django applicationDjangoアプリのデプロイに関するプラクティス / Deploy django application
Djangoアプリのデプロイに関するプラクティス / Deploy django application
Masashi Shibata
 
5 Tips for Writing Better JavaScript
5 Tips for Writing Better JavaScript5 Tips for Writing Better JavaScript
5 Tips for Writing Better JavaScript
Nael El Shawwa
 

What's hot (20)

jQuery Conference Chicago - September 2014
jQuery Conference Chicago - September 2014jQuery Conference Chicago - September 2014
jQuery Conference Chicago - September 2014
 
jQuery Conference San Diego 2014 - Web Performance
jQuery Conference San Diego 2014 - Web PerformancejQuery Conference San Diego 2014 - Web Performance
jQuery Conference San Diego 2014 - Web Performance
 
Rapid Testing, Rapid Development
Rapid Testing, Rapid DevelopmentRapid Testing, Rapid Development
Rapid Testing, Rapid Development
 
AngularJS best-practices
AngularJS best-practicesAngularJS best-practices
AngularJS best-practices
 
Velocity EU 2014 — Offline-first web apps
Velocity EU 2014 — Offline-first web appsVelocity EU 2014 — Offline-first web apps
Velocity EU 2014 — Offline-first web apps
 
Deep dive into AngularJs for Beginners
Deep dive into AngularJs for BeginnersDeep dive into AngularJs for Beginners
Deep dive into AngularJs for Beginners
 
J!Layout Overrides Einstieg und Beispiele
J!Layout Overrides Einstieg und BeispieleJ!Layout Overrides Einstieg und Beispiele
J!Layout Overrides Einstieg und Beispiele
 
Backbone/Marionette introduction
Backbone/Marionette introductionBackbone/Marionette introduction
Backbone/Marionette introduction
 
Hybrid Web Applications
Hybrid Web ApplicationsHybrid Web Applications
Hybrid Web Applications
 
Introduction to Jquery
Introduction to JqueryIntroduction to Jquery
Introduction to Jquery
 
Fronted From Scratch - Supercharge Magento page speed
Fronted From Scratch - Supercharge Magento page speedFronted From Scratch - Supercharge Magento page speed
Fronted From Scratch - Supercharge Magento page speed
 
Making your Angular.js Application accessible
Making your Angular.js Application accessibleMaking your Angular.js Application accessible
Making your Angular.js Application accessible
 
Web view
Web viewWeb view
Web view
 
A Debugging Adventure: Journey through Ember.js Glue
A Debugging Adventure: Journey through Ember.js GlueA Debugging Adventure: Journey through Ember.js Glue
A Debugging Adventure: Journey through Ember.js Glue
 
Accessibility - A feature you can build
Accessibility - A feature you can buildAccessibility - A feature you can build
Accessibility - A feature you can build
 
Javascript done right - Open Web Camp III
Javascript done right - Open Web Camp IIIJavascript done right - Open Web Camp III
Javascript done right - Open Web Camp III
 
Djangoアプリのデプロイに関するプラクティス / Deploy django application
Djangoアプリのデプロイに関するプラクティス / Deploy django applicationDjangoアプリのデプロイに関するプラクティス / Deploy django application
Djangoアプリのデプロイに関するプラクティス / Deploy django application
 
AngularJS for Java Developers
AngularJS for Java DevelopersAngularJS for Java Developers
AngularJS for Java Developers
 
Taking your Web App for a walk
Taking your Web App for a walkTaking your Web App for a walk
Taking your Web App for a walk
 
5 Tips for Writing Better JavaScript
5 Tips for Writing Better JavaScript5 Tips for Writing Better JavaScript
5 Tips for Writing Better JavaScript
 

Similar to Beyond DOM Manipulations: Building Stateful Modules with Events and Promises

Android WebView, The Fifth Element
Android WebView, The Fifth ElementAndroid WebView, The Fifth Element
Android WebView, The Fifth Element
Murat Yener
 
Step by Step Guide for building a simple Struts Application
Step by Step Guide for building a simple Struts ApplicationStep by Step Guide for building a simple Struts Application
Step by Step Guide for building a simple Struts Application
elliando dias
 
Advanced App Building - Tips, Tricks & Lessons Learned
Advanced App Building - Tips, Tricks & Lessons LearnedAdvanced App Building - Tips, Tricks & Lessons Learned
Advanced App Building - Tips, Tricks & Lessons Learned
Jay Graves
 
Automated release management with team city & octopusdeploy - NDC 2013
Automated release management with team city & octopusdeploy - NDC 2013Automated release management with team city & octopusdeploy - NDC 2013
Automated release management with team city & octopusdeploy - NDC 2013
Kristoffer Deinoff
 

Similar to Beyond DOM Manipulations: Building Stateful Modules with Events and Promises (20)

Architecture patterns and practices
Architecture patterns and practicesArchitecture patterns and practices
Architecture patterns and practices
 
Operationalizing Clojure Confidently
Operationalizing Clojure ConfidentlyOperationalizing Clojure Confidently
Operationalizing Clojure Confidently
 
Design Patterns for Mobile Applications
Design Patterns for Mobile ApplicationsDesign Patterns for Mobile Applications
Design Patterns for Mobile Applications
 
Writing SaltStack Modules - OpenWest 2013
Writing SaltStack Modules - OpenWest 2013Writing SaltStack Modules - OpenWest 2013
Writing SaltStack Modules - OpenWest 2013
 
Android WebView, The Fifth Element
Android WebView, The Fifth ElementAndroid WebView, The Fifth Element
Android WebView, The Fifth Element
 
Troubleshooting Live Java Web Applications
Troubleshooting Live Java Web ApplicationsTroubleshooting Live Java Web Applications
Troubleshooting Live Java Web Applications
 
RequireJS
RequireJSRequireJS
RequireJS
 
Keeping it small - Getting to know the Slim PHP micro framework
Keeping it small - Getting to know the Slim PHP micro frameworkKeeping it small - Getting to know the Slim PHP micro framework
Keeping it small - Getting to know the Slim PHP micro framework
 
Step by Step Guide for building a simple Struts Application
Step by Step Guide for building a simple Struts ApplicationStep by Step Guide for building a simple Struts Application
Step by Step Guide for building a simple Struts Application
 
Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)
Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)
Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)
 
Advanced App Building - Tips, Tricks & Lessons Learned
Advanced App Building - Tips, Tricks & Lessons LearnedAdvanced App Building - Tips, Tricks & Lessons Learned
Advanced App Building - Tips, Tricks & Lessons Learned
 
Complex Architectures in Ember
Complex Architectures in EmberComplex Architectures in Ember
Complex Architectures in Ember
 
Building a Startup Stack with AngularJS
Building a Startup Stack with AngularJSBuilding a Startup Stack with AngularJS
Building a Startup Stack with AngularJS
 
Pushing The Boundaries Of Continuous Integration
Pushing The Boundaries Of Continuous IntegrationPushing The Boundaries Of Continuous Integration
Pushing The Boundaries Of Continuous Integration
 
ui-router and $state
ui-router and $stateui-router and $state
ui-router and $state
 
Angular from Scratch
Angular from ScratchAngular from Scratch
Angular from Scratch
 
JavaScript Dependencies, Modules & Browserify
JavaScript Dependencies, Modules & BrowserifyJavaScript Dependencies, Modules & Browserify
JavaScript Dependencies, Modules & Browserify
 
Automated release management with team city & octopusdeploy - NDC 2013
Automated release management with team city & octopusdeploy - NDC 2013Automated release management with team city & octopusdeploy - NDC 2013
Automated release management with team city & octopusdeploy - NDC 2013
 
The InstallShield of the 21st Century – Theo Schlossnagle
The InstallShield of the 21st Century – Theo SchlossnagleThe InstallShield of the 21st Century – Theo Schlossnagle
The InstallShield of the 21st Century – Theo Schlossnagle
 
Generic Setup De-Mystified
Generic Setup De-MystifiedGeneric Setup De-Mystified
Generic Setup De-Mystified
 

Recently uploaded

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
panagenda
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 

Recently uploaded (20)

Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
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
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
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...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 

Beyond DOM Manipulations: Building Stateful Modules with Events and Promises