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

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Recently uploaded (20)

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech 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
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
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
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
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
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 

Beyond DOM Manipulations: Building Stateful Modules with Events and Promises