SlideShare une entreprise Scribd logo
1  sur  40
Télécharger pour lire hors ligne
SO,
       YOU
       THINK
       YOU
       KNOW
       WIDGETS
        @DanielEricLee

Friday, September 16, 2011
DAN LEE

Friday, September 16, 2011
JAVASCRIPT

Friday, September 16, 2011
Friday, September 16, 2011
Stage One: Doubt




Friday, September 16, 2011
Stage Two: Hate




Friday, September 16, 2011
Stage Three: Begrudging Appreciation




Friday, September 16, 2011
Stage Four: Love




Friday, September 16, 2011
FOUR
                                STAGES
                                    OF
                               WIDGET
                             WIZARDRY

Friday, September 16, 2011
Stage One: Wonder




                             I never knew JavaScript could be awesome.


                                                  --My friend Tom




Friday, September 16, 2011
Stage Two: Kicking the Tires




                             With great power, comes...people screwing up.




Friday, September 16, 2011
Alpha Mistake: Accidental Static Fields



             dojo.declare("test.Widget", [ dijit._Widget, dijit._Templated ],{
             	 templateString :
             	 	 dojo.cache("test", "templates/Widget.html"),
             	 	
             	 objectProperty: { } // Well, there goes your afternoon.

             });




Friday, September 16, 2011
Avoiding Accidental Statics


             dojo.declare("test.Widget", [ dijit._Widget, dijit._Templated ], {
             	 templateString :
             	 	 dojo.cache("test", "templates/Widget.html"),
             	
             	 // Initialize to null
             	 objectProperty: null,
             	
             	 // Instantiate in constructor
             	 constructor: function() {
             	 	 this.objectProperty = {};
             	 }
             });




Friday, September 16, 2011
Another Common Stumbling Point



            • Resources and Modules

            • The magic of dojo.require

            • Register Module Path

            • Custom modules when using Dojo from a CDN




Friday, September 16, 2011
You guys already knew this stuff, but....


            • Don’t forget, you are JavaScript Astronauts

                      • You were loading modules when these

                       kids were in diapers


            • Anticipating where newcomers will struggle

             is the most powerful tool of the educator




Friday, September 16, 2011
Stage Three: Gem Mining




                             The Staples® of JavaScript toolkits.
                               “Dojo: Yeah, we’ve got that.”




Friday, September 16, 2011
My favorite gem: Attribute Maps

                             Bind widget properties to widget DOM Nodes.




                Update property, DOM node gets updated automatically.


Friday, September 16, 2011
Widget Attribute Maps


             <!-- In Widget Template HTML -->
             <span data-dojo-attach-point="heroNode"></span>

             // Specified as a property on your widget definition
             attributeMap: {
             	 hero: {
             	 	 node: "heroNode",
             	 	 type: "innerHTML"
             	 }
             }

             // Calling 'set' on hero updates the innerHTML of 'heroNode'
             myWidget.set("hero", "Larry Bird");




Friday, September 16, 2011
Widget Attribute Maps


             // Also possible to bind to a CSS class or HTML attribute
             attributeMap: {
             	 // Bind to a CSS class
             	 prop: {
             	 	 node: "someNode",
             	 	 type: "class"
             	 },
             	 // Bind to an HTML attribute
             	 prop2: {
             	 	 node: "imageNode",
             	 	 type: "attribute",
             	 	 attribute: "src"
             	 }
             }




Friday, September 16, 2011
More Complex Bindings: Custom Setters


              Add function to your widget with naming convention:
              _setPropertynameAttr

              // Whenever widget.set(‘funkiness’, value) is called,
              // this function is called
                _setFunkinessAttr : function(brandNewFunk) {
                  // Do what needs to be done to update the widget
              	    // to the new level of funkiness
                }




Friday, September 16, 2011
One Gotcha...


             _Widget has an attributeMap, don’t clobber it.

             attributeMap:
             	 dojo.delegate(dijit._Widget.prototype.attributeMap, {
             	 	 // Attribute Map definition
             	 })




Friday, September 16, 2011
Gotcha resolved in Dojo 1.7...


             • attributeMap is deprecated, to be removed in Dojo 2.0.

             • All property/DOM bindings can be specified via _set

             convention. To specify an attributeMap relationship, return
             an object instead of a function. Nice.


              _setHeroAttr: { node: "heroNode", type: "innerHTML" }




Friday, September 16, 2011
Demo Time




                             Let’s see those Attribute Maps in action.
                             It’s me. Of course we’ll use a silly widget.




Friday, September 16, 2011
Beware @phiggins




Friday, September 16, 2011
dojo.declare(“poopin.phijit”)




Friday, September 16, 2011
Stay vigilant at DojoConf caughtyapoopin.com




Friday, September 16, 2011
Phijit code: Let’s see a quick demo
            attributeMap: {
            	 threatLevel: {
            	 	 node: "threatLevelNode",
            	 	 type: "class"
            	 }
            },
            _setCounterAttr: function(value) {
            	 var threatCss = "low";
            	
            	 this.counterNode.innerHTML = value;
            	
            	 if(value >= 3 && value <= 4) {
            	 	 threatCss = "elevated";
            	 } else if (value >= 5) {
            	 	 threatCss = "severe";
            	 }
            	 this.set('threatLevel', threatCss);
            }


Friday, September 16, 2011
Stage Four: Craftsmanship




Friday, September 16, 2011
Memory Leaks




                             Historically, not a big deal for web apps.
                                         That time is over.




Friday, September 16, 2011
Tony Gentilcore

                             Web Performance Expert at Google:




                             Awesome blog post about using
                             Chrome’s DevTools Heap Profiler:


              http://gent.ilcore.com/2011/08/finding-memory-leaks.html




Friday, September 16, 2011
Widget Specific Leak


            • Widgets within Widgets can leak

            • Calling destroyRecursive() on a widget generally

             cleans up child widgets
                      • Child widgets defined declaratively in HTML

                       template get cleaned up
                      • Widgets new’d programmatically do not get cleaned up




Friday, September 16, 2011
Example Leaky code

             dojo.declare("poopin.PhijitTriumvirate")

             <!-- Widget Template -->
             <div>
                 <div data-dojo-attach-point="phijits"></div>
             </div>

             postCreate : function() {
             	 for(var i = 0; i < 3; i++) {
             	 	 var p = new poopin.Phijit(); // Leaky Phijit
             	 	 dojo.place(p.domNode, this.phijits, "last");
             	 }
             }




Friday, September 16, 2011
Should I avoid doing this?




                                    No! This is perfectly natural,
                             just make sure you clean up after yourself.




Friday, September 16, 2011
Clean up - Two techniques

    Quick and Dirty:
      • Append your programmatically created widgets to
           this._supportingWidgets
          • Internal, subject to change.


    Better:
      • Keep track of these widgets yourself, destroy them when

          the parent is destroyed.
          • http://higginsforpresident.net/2010/01/widgets-within-widgets/




Friday, September 16, 2011
Lightweight Leak Detection

    dijit.registry to the rescue!


    To detect leaks:
          • Query the registry

          • Perform interactions that should result in net zero widgets

          •Query the registry again to produce a diff




Friday, September 16, 2011
dijit.registry Query code

    // Query the registry
    my_widgets = [];
    dijit.registry.forEach(function(widget){
    	 my_widgets.push(widget.id);
    });
    console.log("Widgets Captured (" + dijit.registry.length + ") in total)");

    // Query it again, produce a Diff
    var leakyWidgets = [];
    dijit.registry.forEach(function(widget){
    	 if(dojo.indexOf(my_widgets, widget.id) === -1) {
    	 	 leakyWidgets.push(widget.declaredClass);
    	 }
    });

    console.log(leakyWidgets.length + " potential leaks found");
    console.log("Potential Leaks: " + leakyWidgets.join(", "));




Friday, September 16, 2011
Bookmarklet Demo




Friday, September 16, 2011
Most Important Stage


            • Stage Two: Kicking the Tires

            • This is where we lose people

            • If you care about Dojo, you should not be OK with this




Friday, September 16, 2011
This is so awesome




Friday, September 16, 2011
THE END.
        @DanielEricLee

Friday, September 16, 2011

Contenu connexe

Tendances

Javascript Prototype Visualized
Javascript Prototype VisualizedJavascript Prototype Visualized
Javascript Prototype Visualized军 沈
 
JavaFX Dependency Injection with FxContainer
JavaFX Dependency Injection with FxContainerJavaFX Dependency Injection with FxContainer
JavaFX Dependency Injection with FxContainerSrikanth Shenoy
 
fuser interface-development-using-jquery
fuser interface-development-using-jqueryfuser interface-development-using-jquery
fuser interface-development-using-jqueryKostas Mavridis
 
Using Objects to Organize your jQuery Code
Using Objects to Organize your jQuery CodeUsing Objects to Organize your jQuery Code
Using Objects to Organize your jQuery CodeRebecca Murphey
 
Dependency Inversion and Dependency Injection in PHP
Dependency Inversion and Dependency Injection in PHPDependency Inversion and Dependency Injection in PHP
Dependency Inversion and Dependency Injection in PHPmtoppa
 
Developing components and extensions for ext js
Developing components and extensions for ext jsDeveloping components and extensions for ext js
Developing components and extensions for ext jsMats Bryntse
 
jQuery Features to Avoid
jQuery Features to AvoidjQuery Features to Avoid
jQuery Features to Avoiddmethvin
 
Secrets of JavaScript Libraries
Secrets of JavaScript LibrariesSecrets of JavaScript Libraries
Secrets of JavaScript Librariesjeresig
 
Advanced CPP Lecture 2- Summer School 2014 - ACA CSE IITK
Advanced CPP Lecture 2- Summer School 2014 - ACA CSE IITKAdvanced CPP Lecture 2- Summer School 2014 - ACA CSE IITK
Advanced CPP Lecture 2- Summer School 2014 - ACA CSE IITKPankaj Prateek
 
Future-proofing Your JavaScript Apps (Compact edition)
Future-proofing Your JavaScript Apps (Compact edition)Future-proofing Your JavaScript Apps (Compact edition)
Future-proofing Your JavaScript Apps (Compact edition)Addy Osmani
 
Mulberry: A Mobile App Development Toolkit
Mulberry: A Mobile App Development ToolkitMulberry: A Mobile App Development Toolkit
Mulberry: A Mobile App Development ToolkitRebecca Murphey
 
JavaScript - From Birth To Closure
JavaScript - From Birth To ClosureJavaScript - From Birth To Closure
JavaScript - From Birth To ClosureRobert Nyman
 

Tendances (20)

Javascript Prototype Visualized
Javascript Prototype VisualizedJavascript Prototype Visualized
Javascript Prototype Visualized
 
JavaFX Dependency Injection with FxContainer
JavaFX Dependency Injection with FxContainerJavaFX Dependency Injection with FxContainer
JavaFX Dependency Injection with FxContainer
 
Prototype
PrototypePrototype
Prototype
 
fuser interface-development-using-jquery
fuser interface-development-using-jqueryfuser interface-development-using-jquery
fuser interface-development-using-jquery
 
Using Objects to Organize your jQuery Code
Using Objects to Organize your jQuery CodeUsing Objects to Organize your jQuery Code
Using Objects to Organize your jQuery Code
 
Inside jQuery (2011)
Inside jQuery (2011)Inside jQuery (2011)
Inside jQuery (2011)
 
Js: master prototypes
Js: master prototypesJs: master prototypes
Js: master prototypes
 
Dojo Confessions
Dojo ConfessionsDojo Confessions
Dojo Confessions
 
Dependency Inversion and Dependency Injection in PHP
Dependency Inversion and Dependency Injection in PHPDependency Inversion and Dependency Injection in PHP
Dependency Inversion and Dependency Injection in PHP
 
has("builds")
has("builds")has("builds")
has("builds")
 
dojo.things()
dojo.things()dojo.things()
dojo.things()
 
Developing components and extensions for ext js
Developing components and extensions for ext jsDeveloping components and extensions for ext js
Developing components and extensions for ext js
 
jQuery Features to Avoid
jQuery Features to AvoidjQuery Features to Avoid
jQuery Features to Avoid
 
Secrets of JavaScript Libraries
Secrets of JavaScript LibrariesSecrets of JavaScript Libraries
Secrets of JavaScript Libraries
 
Javascript in Plone
Javascript in PloneJavascript in Plone
Javascript in Plone
 
Advanced CPP Lecture 2- Summer School 2014 - ACA CSE IITK
Advanced CPP Lecture 2- Summer School 2014 - ACA CSE IITKAdvanced CPP Lecture 2- Summer School 2014 - ACA CSE IITK
Advanced CPP Lecture 2- Summer School 2014 - ACA CSE IITK
 
Future-proofing Your JavaScript Apps (Compact edition)
Future-proofing Your JavaScript Apps (Compact edition)Future-proofing Your JavaScript Apps (Compact edition)
Future-proofing Your JavaScript Apps (Compact edition)
 
Javascript Design Patterns
Javascript Design PatternsJavascript Design Patterns
Javascript Design Patterns
 
Mulberry: A Mobile App Development Toolkit
Mulberry: A Mobile App Development ToolkitMulberry: A Mobile App Development Toolkit
Mulberry: A Mobile App Development Toolkit
 
JavaScript - From Birth To Closure
JavaScript - From Birth To ClosureJavaScript - From Birth To Closure
JavaScript - From Birth To Closure
 

En vedette

PRA100 Presentation Skills in Communication
PRA100 Presentation Skills in CommunicationPRA100 Presentation Skills in Communication
PRA100 Presentation Skills in CommunicationHakan Turkkusu
 
Meyve hastalik ve zararlilari ilaç
Meyve hastalik ve zararlilari ilaçMeyve hastalik ve zararlilari ilaç
Meyve hastalik ve zararlilari ilaçadex25
 
Süs bitkileri hastalik ve zararlilari
Süs bitkileri hastalik ve zararlilariSüs bitkileri hastalik ve zararlilari
Süs bitkileri hastalik ve zararlilariadex25
 
Absolute Intelligence Theorem
Absolute Intelligence TheoremAbsolute Intelligence Theorem
Absolute Intelligence TheoremManoj T. Panchal
 
2014 REVISTA MEXICANA DE CIENCIAS GEOLÓGICAS - Study of Cedral Horses and the...
2014 REVISTA MEXICANA DE CIENCIAS GEOLÓGICAS - Study of Cedral Horses and the...2014 REVISTA MEXICANA DE CIENCIAS GEOLÓGICAS - Study of Cedral Horses and the...
2014 REVISTA MEXICANA DE CIENCIAS GEOLÓGICAS - Study of Cedral Horses and the...Ruben LLumihucci
 
Clarion Corporate Presentation
Clarion Corporate PresentationClarion Corporate Presentation
Clarion Corporate PresentationClarion Marketing
 
ใบงานที่ 2-8
ใบงานที่ 2-8ใบงานที่ 2-8
ใบงานที่ 2-8Robotto' Data
 
Kaliteli sofralik uzum yetistiriciligi
Kaliteli sofralik uzum yetistiriciligi Kaliteli sofralik uzum yetistiriciligi
Kaliteli sofralik uzum yetistiriciligi adex25
 
Käthe Kollwitz Krieg Freiwillige
Käthe Kollwitz Krieg FreiwilligeKäthe Kollwitz Krieg Freiwillige
Käthe Kollwitz Krieg FreiwilligeDimitri Kokkonis
 
Comber planing mills
Comber planing millsComber planing mills
Comber planing millsAsif Raza
 
二醫技三A 17號 林芸萱(小書)[1]
二醫技三A 17號 林芸萱(小書)[1]二醫技三A 17號 林芸萱(小書)[1]
二醫技三A 17號 林芸萱(小書)[1]輝 哲
 
Tugas hari senin
Tugas hari seninTugas hari senin
Tugas hari seninApin Yasin
 

En vedette (20)

PRA100 Presentation Skills in Communication
PRA100 Presentation Skills in CommunicationPRA100 Presentation Skills in Communication
PRA100 Presentation Skills in Communication
 
Meyve hastalik ve zararlilari ilaç
Meyve hastalik ve zararlilari ilaçMeyve hastalik ve zararlilari ilaç
Meyve hastalik ve zararlilari ilaç
 
Süs bitkileri hastalik ve zararlilari
Süs bitkileri hastalik ve zararlilariSüs bitkileri hastalik ve zararlilari
Süs bitkileri hastalik ve zararlilari
 
Computer 9
Computer 9Computer 9
Computer 9
 
Absolute Intelligence Theorem
Absolute Intelligence TheoremAbsolute Intelligence Theorem
Absolute Intelligence Theorem
 
Tugas 11
Tugas 11Tugas 11
Tugas 11
 
2014 REVISTA MEXICANA DE CIENCIAS GEOLÓGICAS - Study of Cedral Horses and the...
2014 REVISTA MEXICANA DE CIENCIAS GEOLÓGICAS - Study of Cedral Horses and the...2014 REVISTA MEXICANA DE CIENCIAS GEOLÓGICAS - Study of Cedral Horses and the...
2014 REVISTA MEXICANA DE CIENCIAS GEOLÓGICAS - Study of Cedral Horses and the...
 
Censorship
CensorshipCensorship
Censorship
 
Clarion Corporate Presentation
Clarion Corporate PresentationClarion Corporate Presentation
Clarion Corporate Presentation
 
ใบงานที่ 2-8
ใบงานที่ 2-8ใบงานที่ 2-8
ใบงานที่ 2-8
 
Kaliteli sofralik uzum yetistiriciligi
Kaliteli sofralik uzum yetistiriciligi Kaliteli sofralik uzum yetistiriciligi
Kaliteli sofralik uzum yetistiriciligi
 
Käthe Kollwitz Krieg Freiwillige
Käthe Kollwitz Krieg FreiwilligeKäthe Kollwitz Krieg Freiwillige
Käthe Kollwitz Krieg Freiwillige
 
RAPPORTO EXPORT ABRUZZO
RAPPORTO EXPORT ABRUZZORAPPORTO EXPORT ABRUZZO
RAPPORTO EXPORT ABRUZZO
 
лагерь
лагерьлагерь
лагерь
 
Comber planing mills
Comber planing millsComber planing mills
Comber planing mills
 
Daily life at uk 1
Daily life at uk 1Daily life at uk 1
Daily life at uk 1
 
PIA AA AD16.
PIA AA AD16.PIA AA AD16.
PIA AA AD16.
 
Batxi 2 ex.
Batxi 2 ex.Batxi 2 ex.
Batxi 2 ex.
 
二醫技三A 17號 林芸萱(小書)[1]
二醫技三A 17號 林芸萱(小書)[1]二醫技三A 17號 林芸萱(小書)[1]
二醫技三A 17號 林芸萱(小書)[1]
 
Tugas hari senin
Tugas hari seninTugas hari senin
Tugas hari senin
 

Similaire à Four Stages of Widget Wizardry and Avoiding Memory Leaks

Integrate Spring MVC with RequireJS & Backbone.js & Spring Data JPA
Integrate Spring MVC with RequireJS & Backbone.js & Spring Data JPAIntegrate Spring MVC with RequireJS & Backbone.js & Spring Data JPA
Integrate Spring MVC with RequireJS & Backbone.js & Spring Data JPACheng Ta Yeh
 
[Ultracode Munich #4] Short introduction to the new Android build system incl...
[Ultracode Munich #4] Short introduction to the new Android build system incl...[Ultracode Munich #4] Short introduction to the new Android build system incl...
[Ultracode Munich #4] Short introduction to the new Android build system incl...BeMyApp
 
Moving to Dojo 1.7 and the path to 2.0
Moving to Dojo 1.7 and the path to 2.0Moving to Dojo 1.7 and the path to 2.0
Moving to Dojo 1.7 and the path to 2.0James Thomas
 
Symfony War Stories
Symfony War StoriesSymfony War Stories
Symfony War StoriesJakub Zalas
 
JavaScript Libraries: The Big Picture
JavaScript Libraries: The Big PictureJavaScript Libraries: The Big Picture
JavaScript Libraries: The Big PictureSimon Willison
 
Unlearning and Relearning jQuery - Client-side Performance Optimization
Unlearning and Relearning jQuery - Client-side Performance OptimizationUnlearning and Relearning jQuery - Client-side Performance Optimization
Unlearning and Relearning jQuery - Client-side Performance OptimizationJon Dean
 
JavaScript: DOM and jQuery
JavaScript: DOM and jQueryJavaScript: DOM and jQuery
JavaScript: DOM and jQuery維佋 唐
 
Getting started with Verold and Three.js
Getting started with Verold and Three.jsGetting started with Verold and Three.js
Getting started with Verold and Three.jsVerold
 
My Favourite 10 Things about Xcode/ObjectiveC
My Favourite 10 Things about Xcode/ObjectiveCMy Favourite 10 Things about Xcode/ObjectiveC
My Favourite 10 Things about Xcode/ObjectiveCJohnKennedy
 
Debugging: Or How I Learned To Stop Worrying and Love EXC_BAD_ACCESS
Debugging: Or How I Learned To Stop Worrying and Love EXC_BAD_ACCESSDebugging: Or How I Learned To Stop Worrying and Love EXC_BAD_ACCESS
Debugging: Or How I Learned To Stop Worrying and Love EXC_BAD_ACCESSartgillespie
 
The Naked Bundle - Symfony Live London 2014
The Naked Bundle - Symfony Live London 2014The Naked Bundle - Symfony Live London 2014
The Naked Bundle - Symfony Live London 2014Matthias Noback
 
Rapid web development using tornado web and mongodb
Rapid web development using tornado web and mongodbRapid web development using tornado web and mongodb
Rapid web development using tornado web and mongodbikailan
 
Singletons in PHP - Why they are bad and how you can eliminate them from your...
Singletons in PHP - Why they are bad and how you can eliminate them from your...Singletons in PHP - Why they are bad and how you can eliminate them from your...
Singletons in PHP - Why they are bad and how you can eliminate them from your...go_oh
 
Javascript essential-pattern
Javascript essential-patternJavascript essential-pattern
Javascript essential-pattern偉格 高
 
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
 
React Native custom components
React Native custom componentsReact Native custom components
React Native custom componentsJeremy Grancher
 
jQuery with javascript training by Technnovation Labs
jQuery with javascript training by Technnovation LabsjQuery with javascript training by Technnovation Labs
jQuery with javascript training by Technnovation LabsPrasad Shende
 

Similaire à Four Stages of Widget Wizardry and Avoiding Memory Leaks (20)

Integrate Spring MVC with RequireJS & Backbone.js & Spring Data JPA
Integrate Spring MVC with RequireJS & Backbone.js & Spring Data JPAIntegrate Spring MVC with RequireJS & Backbone.js & Spring Data JPA
Integrate Spring MVC with RequireJS & Backbone.js & Spring Data JPA
 
[Ultracode Munich #4] Short introduction to the new Android build system incl...
[Ultracode Munich #4] Short introduction to the new Android build system incl...[Ultracode Munich #4] Short introduction to the new Android build system incl...
[Ultracode Munich #4] Short introduction to the new Android build system incl...
 
Moving to Dojo 1.7 and the path to 2.0
Moving to Dojo 1.7 and the path to 2.0Moving to Dojo 1.7 and the path to 2.0
Moving to Dojo 1.7 and the path to 2.0
 
Symfony War Stories
Symfony War StoriesSymfony War Stories
Symfony War Stories
 
JavaScript Libraries: The Big Picture
JavaScript Libraries: The Big PictureJavaScript Libraries: The Big Picture
JavaScript Libraries: The Big Picture
 
Unlearning and Relearning jQuery - Client-side Performance Optimization
Unlearning and Relearning jQuery - Client-side Performance OptimizationUnlearning and Relearning jQuery - Client-side Performance Optimization
Unlearning and Relearning jQuery - Client-side Performance Optimization
 
JavaScript: DOM and jQuery
JavaScript: DOM and jQueryJavaScript: DOM and jQuery
JavaScript: DOM and jQuery
 
Testable Javascript
Testable JavascriptTestable Javascript
Testable Javascript
 
Getting started with Verold and Three.js
Getting started with Verold and Three.jsGetting started with Verold and Three.js
Getting started with Verold and Three.js
 
JavaScript Basics
JavaScript BasicsJavaScript Basics
JavaScript Basics
 
My Favourite 10 Things about Xcode/ObjectiveC
My Favourite 10 Things about Xcode/ObjectiveCMy Favourite 10 Things about Xcode/ObjectiveC
My Favourite 10 Things about Xcode/ObjectiveC
 
Debugging: Or How I Learned To Stop Worrying and Love EXC_BAD_ACCESS
Debugging: Or How I Learned To Stop Worrying and Love EXC_BAD_ACCESSDebugging: Or How I Learned To Stop Worrying and Love EXC_BAD_ACCESS
Debugging: Or How I Learned To Stop Worrying and Love EXC_BAD_ACCESS
 
The Naked Bundle - Symfony Live London 2014
The Naked Bundle - Symfony Live London 2014The Naked Bundle - Symfony Live London 2014
The Naked Bundle - Symfony Live London 2014
 
Rapid web development using tornado web and mongodb
Rapid web development using tornado web and mongodbRapid web development using tornado web and mongodb
Rapid web development using tornado web and mongodb
 
Singletons in PHP - Why they are bad and how you can eliminate them from your...
Singletons in PHP - Why they are bad and how you can eliminate them from your...Singletons in PHP - Why they are bad and how you can eliminate them from your...
Singletons in PHP - Why they are bad and how you can eliminate them from your...
 
Javascript essential-pattern
Javascript essential-patternJavascript essential-pattern
Javascript essential-pattern
 
jQuery
jQueryjQuery
jQuery
 
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
 
React Native custom components
React Native custom componentsReact Native custom components
React Native custom components
 
jQuery with javascript training by Technnovation Labs
jQuery with javascript training by Technnovation LabsjQuery with javascript training by Technnovation Labs
jQuery with javascript training by Technnovation Labs
 

Dernier

"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
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
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
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
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
 

Dernier (20)

"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
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
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
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
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
 

Four Stages of Widget Wizardry and Avoiding Memory Leaks

  • 1. SO, YOU THINK YOU KNOW WIDGETS @DanielEricLee Friday, September 16, 2011
  • 5. Stage One: Doubt Friday, September 16, 2011
  • 6. Stage Two: Hate Friday, September 16, 2011
  • 7. Stage Three: Begrudging Appreciation Friday, September 16, 2011
  • 8. Stage Four: Love Friday, September 16, 2011
  • 9. FOUR STAGES OF WIDGET WIZARDRY Friday, September 16, 2011
  • 10. Stage One: Wonder I never knew JavaScript could be awesome. --My friend Tom Friday, September 16, 2011
  • 11. Stage Two: Kicking the Tires With great power, comes...people screwing up. Friday, September 16, 2011
  • 12. Alpha Mistake: Accidental Static Fields dojo.declare("test.Widget", [ dijit._Widget, dijit._Templated ],{ templateString : dojo.cache("test", "templates/Widget.html"), objectProperty: { } // Well, there goes your afternoon. }); Friday, September 16, 2011
  • 13. Avoiding Accidental Statics dojo.declare("test.Widget", [ dijit._Widget, dijit._Templated ], { templateString : dojo.cache("test", "templates/Widget.html"), // Initialize to null objectProperty: null, // Instantiate in constructor constructor: function() { this.objectProperty = {}; } }); Friday, September 16, 2011
  • 14. Another Common Stumbling Point • Resources and Modules • The magic of dojo.require • Register Module Path • Custom modules when using Dojo from a CDN Friday, September 16, 2011
  • 15. You guys already knew this stuff, but.... • Don’t forget, you are JavaScript Astronauts • You were loading modules when these kids were in diapers • Anticipating where newcomers will struggle is the most powerful tool of the educator Friday, September 16, 2011
  • 16. Stage Three: Gem Mining The Staples® of JavaScript toolkits. “Dojo: Yeah, we’ve got that.” Friday, September 16, 2011
  • 17. My favorite gem: Attribute Maps Bind widget properties to widget DOM Nodes. Update property, DOM node gets updated automatically. Friday, September 16, 2011
  • 18. Widget Attribute Maps <!-- In Widget Template HTML --> <span data-dojo-attach-point="heroNode"></span> // Specified as a property on your widget definition attributeMap: { hero: { node: "heroNode", type: "innerHTML" } } // Calling 'set' on hero updates the innerHTML of 'heroNode' myWidget.set("hero", "Larry Bird"); Friday, September 16, 2011
  • 19. Widget Attribute Maps // Also possible to bind to a CSS class or HTML attribute attributeMap: { // Bind to a CSS class prop: { node: "someNode", type: "class" }, // Bind to an HTML attribute prop2: { node: "imageNode", type: "attribute", attribute: "src" } } Friday, September 16, 2011
  • 20. More Complex Bindings: Custom Setters Add function to your widget with naming convention: _setPropertynameAttr // Whenever widget.set(‘funkiness’, value) is called, // this function is called _setFunkinessAttr : function(brandNewFunk) { // Do what needs to be done to update the widget // to the new level of funkiness } Friday, September 16, 2011
  • 21. One Gotcha... _Widget has an attributeMap, don’t clobber it. attributeMap: dojo.delegate(dijit._Widget.prototype.attributeMap, { // Attribute Map definition }) Friday, September 16, 2011
  • 22. Gotcha resolved in Dojo 1.7... • attributeMap is deprecated, to be removed in Dojo 2.0. • All property/DOM bindings can be specified via _set convention. To specify an attributeMap relationship, return an object instead of a function. Nice. _setHeroAttr: { node: "heroNode", type: "innerHTML" } Friday, September 16, 2011
  • 23. Demo Time Let’s see those Attribute Maps in action. It’s me. Of course we’ll use a silly widget. Friday, September 16, 2011
  • 26. Stay vigilant at DojoConf caughtyapoopin.com Friday, September 16, 2011
  • 27. Phijit code: Let’s see a quick demo attributeMap: { threatLevel: { node: "threatLevelNode", type: "class" } }, _setCounterAttr: function(value) { var threatCss = "low"; this.counterNode.innerHTML = value; if(value >= 3 && value <= 4) { threatCss = "elevated"; } else if (value >= 5) { threatCss = "severe"; } this.set('threatLevel', threatCss); } Friday, September 16, 2011
  • 28. Stage Four: Craftsmanship Friday, September 16, 2011
  • 29. Memory Leaks Historically, not a big deal for web apps. That time is over. Friday, September 16, 2011
  • 30. Tony Gentilcore Web Performance Expert at Google: Awesome blog post about using Chrome’s DevTools Heap Profiler: http://gent.ilcore.com/2011/08/finding-memory-leaks.html Friday, September 16, 2011
  • 31. Widget Specific Leak • Widgets within Widgets can leak • Calling destroyRecursive() on a widget generally cleans up child widgets • Child widgets defined declaratively in HTML template get cleaned up • Widgets new’d programmatically do not get cleaned up Friday, September 16, 2011
  • 32. Example Leaky code dojo.declare("poopin.PhijitTriumvirate") <!-- Widget Template --> <div> <div data-dojo-attach-point="phijits"></div> </div> postCreate : function() { for(var i = 0; i < 3; i++) { var p = new poopin.Phijit(); // Leaky Phijit dojo.place(p.domNode, this.phijits, "last"); } } Friday, September 16, 2011
  • 33. Should I avoid doing this? No! This is perfectly natural, just make sure you clean up after yourself. Friday, September 16, 2011
  • 34. Clean up - Two techniques Quick and Dirty: • Append your programmatically created widgets to this._supportingWidgets • Internal, subject to change. Better: • Keep track of these widgets yourself, destroy them when the parent is destroyed. • http://higginsforpresident.net/2010/01/widgets-within-widgets/ Friday, September 16, 2011
  • 35. Lightweight Leak Detection dijit.registry to the rescue! To detect leaks: • Query the registry • Perform interactions that should result in net zero widgets •Query the registry again to produce a diff Friday, September 16, 2011
  • 36. dijit.registry Query code // Query the registry my_widgets = []; dijit.registry.forEach(function(widget){ my_widgets.push(widget.id); }); console.log("Widgets Captured (" + dijit.registry.length + ") in total)"); // Query it again, produce a Diff var leakyWidgets = []; dijit.registry.forEach(function(widget){ if(dojo.indexOf(my_widgets, widget.id) === -1) { leakyWidgets.push(widget.declaredClass); } }); console.log(leakyWidgets.length + " potential leaks found"); console.log("Potential Leaks: " + leakyWidgets.join(", ")); Friday, September 16, 2011
  • 38. Most Important Stage • Stage Two: Kicking the Tires • This is where we lose people • If you care about Dojo, you should not be OK with this Friday, September 16, 2011
  • 39. This is so awesome Friday, September 16, 2011
  • 40. THE END. @DanielEricLee Friday, September 16, 2011