Canjs

B
http://canjs.us
@canjsus
Why?
• Prevents Leaks
• Ease of Use
• Fast
What’s Inside
• can.Construct
• can.Observe
• can.Model
• can.Control
• can.view
• can.EJS
• can.route
can.Construct(static, proto)
var Person = can.Construct({
    init : function (name) {
       this.name = name;
    }
});

var curtis = new Person("Curtis");
curtis.name
new can.Observe(data)
var person =
  new can.Observe({ name: 'josh'});

person.bind('name‟, function(ev,newVal,oldVal){
  newVal //-> 'Josh Dean'
  oldVal //-> 'josh'
});

person.attr('name') //-> 'josh'
person.name //-> 'josh'
person.attr('name','Josh Dean‟);
can.Model(ajax,proto)
var Todo = can.Model({
  findAll : '/todo',
  findOne : '/todo/{id}',
  destroy : 'POST /todo/destroy/{id}',
  update : 'POST /todo/{id}',
  create : '/todo'
},{});

Todo.findOne({id: 5}, function( todo ) {
  todo.attr('name')
});
can.Control(proto)
var Tabs = can.Control({
  init: function( el ) {
     // show first tab
  },
  'li click': function( el, ev ) {
     // hide other tabs
     // show selected tab
  }
});

new Tabs('#tabs');
can.route(route, defaults)
var Routing = can.Control({
 ':type/:id route': function( data ) {

  }
})

new Routing( document.body );
can.route.attr( { type : 'todos', id: 5 } )
can.view( idOrURL, data ) -> fragment

<script type='text/ejs' id='messageEJS'>
 <h1><%= message %></h1>
</script>

can.view('messageEJS', {
  message : 'Hello World'
}) //-> frag <h1>Hello World</h1>
EmbeddedJS Templates

Favorite tag is <%= ‟<blink>Blink</blink>‟ %>

-> My favorite tag is <blink>Blink</blink>




Favorite tag is <%== ‟<blink>Blink</blink>‟ %>

-> Favorite tag is Blink
EmbeddedJS Templates
<% if( devs ) { %>
 <% for( var i = 0; i < devs.length; i++ ) { %>
  <li><%= arr[i] %></li>
 <% } %>
<% } else { %>
 <li>No Developers</li>
<% } %>

can.view('devs.ejs',{devs: ['Andy','Fred']})
//-> frag <li>Andy</li><li>Fred</li>
EJS Live Binding
<% if( devs.attr('length') ) { %>
 <% list(devs, function(dev){ %>
  <li><%= dev.attr(„name‟) %></li>
 <% }) %>
<% } else { %>
 <li>No Developers</li>
<% } %>

var devs = new can.Observe.List([
  {name : 'Andy'}, {name : 'Fred'}
])

can.view('devs.ejs',{devs : devs})
//-> frag <li>Andy</li><li>Fred</li>
Why?
• Prevents Leaks
• Speed
• Flexibility + Libraries
• Ease of Use
• Features vs Size
A tooltip.



                                  Undo




$('#undo').bind('mouseenter',function(){
  $('<div>Undo</div>').tooltipFor(this)
})
What’s Wrong?
$.fn.tooltipFor = function(anchor){
 var $el = this
    .appendTo(document.body)
    .offset( $(anchor).offset() )

    $(anchor).bind('mouseleave',function(ev){
       $el.remove()
    })
}
Leaks
Templated Events “{option} eventName”
Templated Events
var Tooltip = can.Control({
  init: function( el, options ) {
    el.appendTo(document.body)
      .offset( $(options.anchor).offset() )
  },
  '{anchor} mouseleave': function( el, ev ) {
    this.element.remove();
  }
});

new Tooltip($('<div>Undo</div>'),{
  anchor : this
});
Non-leaking Global Store

          Critical           Due Today


     File Taxes            Brush Teeth

     Write talk on CanJS   Write talk on CanJS

     Emissions Test        Check into flight
Non-leaking Global Store

             Awesome Developers
Easy To Use
Plugins
• Validations
• Getter / Setter
• Serialize / Deserialize
• Backup / Restore
• Super
• Proxy


$(“#todos”).html( „todos.ejs‟, Todo.findAll() )
can.Control and Backbone.View




                     http://jsperf.com/tabs-timing-test
Live Binding




               http://jsfiddle.net/JMWf4/5/
Live Binding




*can.zepto.js, angular/ember not tested, ask me why   http://jsperf.com/canjs-ejs-live-bind
Features vs Size
 CanJS 8.49kb      - jQuery


 Backbone 8.97kb   -jQuery
                   +Underscore

 Knockout 13kb     none


 Batman 15kb       -pollyfills for ES5


                   none
 Angular 24kb

                   -jQuery
 Ember 39kb        +metamorph.js
Library Support
Questions?


         safer
        faster
       easier
       smaller
     library-er

  http://canjs.us
    @canjsus
1 sur 28

Recommandé

Canjs par
CanjsCanjs
CanjsCherif Bouchelaghem
1.5K vues67 diapositives
RequireJS par
RequireJSRequireJS
RequireJSSebastiano Armeli
5.5K vues73 diapositives
Railsbridge javascript par
Railsbridge   javascriptRailsbridge   javascript
Railsbridge javascriptp4geoff
185 vues15 diapositives
Casl. isomorphic permission management.pptx par
Casl. isomorphic permission management.pptxCasl. isomorphic permission management.pptx
Casl. isomorphic permission management.pptxSergiy Stotskiy
114 vues36 diapositives
Requirejs par
RequirejsRequirejs
Requirejssioked
3.4K vues16 diapositives
Build web application by express par
Build web application by expressBuild web application by express
Build web application by expressShawn Meng
619 vues34 diapositives

Contenu connexe

Tendances

Human Talks Riot.js par
Human Talks Riot.jsHuman Talks Riot.js
Human Talks Riot.jsstreamdata.io
748 vues15 diapositives
NodeJS in Windows Azure par
NodeJS in Windows AzureNodeJS in Windows Azure
NodeJS in Windows AzureJesus Rodriguez
1.6K vues37 diapositives
jQuery in 15 minutes par
jQuery in 15 minutesjQuery in 15 minutes
jQuery in 15 minutesSimon Willison
41.5K vues14 diapositives
Laravel 로 배우는 서버사이드 #5 par
Laravel 로 배우는 서버사이드 #5Laravel 로 배우는 서버사이드 #5
Laravel 로 배우는 서버사이드 #5성일 한
2.6K vues51 diapositives
Introduction to jQuery - Barcamp London 9 par
Introduction to jQuery - Barcamp London 9Introduction to jQuery - Barcamp London 9
Introduction to jQuery - Barcamp London 9Jack Franklin
612 vues29 diapositives
OUTDATED (Encore) par
OUTDATED (Encore)OUTDATED (Encore)
OUTDATED (Encore)Stefan Adolf
117 vues19 diapositives

Tendances(20)

Laravel 로 배우는 서버사이드 #5 par 성일 한
Laravel 로 배우는 서버사이드 #5Laravel 로 배우는 서버사이드 #5
Laravel 로 배우는 서버사이드 #5
성일 한2.6K vues
Introduction to jQuery - Barcamp London 9 par Jack Franklin
Introduction to jQuery - Barcamp London 9Introduction to jQuery - Barcamp London 9
Introduction to jQuery - Barcamp London 9
Jack Franklin612 vues
Angular JS Routing par kennystoltz
Angular JS RoutingAngular JS Routing
Angular JS Routing
kennystoltz6.7K vues
лукьянченко л.а. пос 10а par l10bov
лукьянченко л.а. пос 10алукьянченко л.а. пос 10а
лукьянченко л.а. пос 10а
l10bov233 vues
Angular Promises and Advanced Routing par Alexe Bogdan
Angular Promises and Advanced RoutingAngular Promises and Advanced Routing
Angular Promises and Advanced Routing
Alexe Bogdan3.2K vues
Backbone.js par VO Tho
Backbone.jsBackbone.js
Backbone.js
VO Tho6.7K vues
Criando um componente de busca com AngularJS par Douglas Lira
Criando um componente de busca com AngularJSCriando um componente de busca com AngularJS
Criando um componente de busca com AngularJS
Douglas Lira2.9K vues
Damage Control par sintaxi
Damage ControlDamage Control
Damage Control
sintaxi770 vues
Ember: Guts & Goals par Bob Lail
Ember: Guts & GoalsEmber: Guts & Goals
Ember: Guts & Goals
Bob Lail313 vues

En vedette

Bending the Rules: Community over Code over Policy. par
Bending the Rules: Community over Code over Policy.Bending the Rules: Community over Code over Policy.
Bending the Rules: Community over Code over Policy.pescetti
5.7K vues31 diapositives
Open Development in the Enterprise, October 2013 edition par
Open Development in the Enterprise, October 2013 editionOpen Development in the Enterprise, October 2013 edition
Open Development in the Enterprise, October 2013 editionBertrand Delacretaz
4.9K vues31 diapositives
Open Source In Education par
Open Source In EducationOpen Source In Education
Open Source In EducationBertrand Delacretaz
4.8K vues31 diapositives
Dev cloud par
Dev cloudDev cloud
Dev cloudRajesh Battala
2.6K vues13 diapositives
Open Source enables Open Innovation par
Open Source enables Open InnovationOpen Source enables Open Innovation
Open Source enables Open InnovationBertrand Delacretaz
19.7K vues39 diapositives
Life in Open Source Communities, ApacheCon US 2009 par
Life in Open Source Communities, ApacheCon US 2009Life in Open Source Communities, ApacheCon US 2009
Life in Open Source Communities, ApacheCon US 2009Bertrand Delacretaz
5.3K vues40 diapositives

En vedette(16)

Bending the Rules: Community over Code over Policy. par pescetti
Bending the Rules: Community over Code over Policy.Bending the Rules: Community over Code over Policy.
Bending the Rules: Community over Code over Policy.
pescetti5.7K vues
Open Development in the Enterprise, October 2013 edition par Bertrand Delacretaz
Open Development in the Enterprise, October 2013 editionOpen Development in the Enterprise, October 2013 edition
Open Development in the Enterprise, October 2013 edition
Life in Open Source Communities, ApacheCon US 2009 par Bertrand Delacretaz
Life in Open Source Communities, ApacheCon US 2009Life in Open Source Communities, ApacheCon US 2009
Life in Open Source Communities, ApacheCon US 2009
Keynote apache bd-eu-nov-2016 par alanfgates
Keynote apache bd-eu-nov-2016Keynote apache bd-eu-nov-2016
Keynote apache bd-eu-nov-2016
alanfgates3.6K vues
Hortonworks apache training par alanfgates
Hortonworks apache trainingHortonworks apache training
Hortonworks apache training
alanfgates4.3K vues
Open Source at scale: the Apache Software Foundation par Bertrand Delacretaz
Open Source at scale: the Apache Software FoundationOpen Source at scale: the Apache Software Foundation
Open Source at scale: the Apache Software Foundation
Open-Source Collaboration Tools are Good for You - 2009 edition par Bertrand Delacretaz
Open-Source Collaboration Tools are Good for You - 2009 editionOpen-Source Collaboration Tools are Good for You - 2009 edition
Open-Source Collaboration Tools are Good for You - 2009 edition
Why Docker par dotCloud
Why DockerWhy Docker
Why Docker
dotCloud310.6K vues
Gardler bosc2010 community_developmentattheasf par BOSC 2010
Gardler bosc2010 community_developmentattheasfGardler bosc2010 community_developmentattheasf
Gardler bosc2010 community_developmentattheasf
BOSC 20105.1K vues
Successfully Profiting From Apache Brands par Shane Curcuru
Successfully Profiting From Apache BrandsSuccessfully Profiting From Apache Brands
Successfully Profiting From Apache Brands
Shane Curcuru2.7K vues
Improving Your Apache Project's Image And Brand par Shane Curcuru
 Improving Your Apache Project's Image And Brand Improving Your Apache Project's Image And Brand
Improving Your Apache Project's Image And Brand
Shane Curcuru2.7K vues
Practical Trademark Law for FOSS Projects par Shane Curcuru
Practical Trademark Law for FOSS ProjectsPractical Trademark Law for FOSS Projects
Practical Trademark Law for FOSS Projects
Shane Curcuru4.2K vues

Similaire à Canjs

Summit2014 topic 0066 - 10 enhancements that require 10 lines of code par
Summit2014 topic 0066 - 10 enhancements that require 10 lines of codeSummit2014 topic 0066 - 10 enhancements that require 10 lines of code
Summit2014 topic 0066 - 10 enhancements that require 10 lines of codeAngel Borroy López
743 vues64 diapositives
Assetic (Zendcon) par
Assetic (Zendcon)Assetic (Zendcon)
Assetic (Zendcon)Kris Wallsmith
1.8K vues107 diapositives
Javascript first-class citizenery par
Javascript first-class citizeneryJavascript first-class citizenery
Javascript first-class citizenerytoddbr
1.2K vues32 diapositives
Assetic (OSCON) par
Assetic (OSCON)Assetic (OSCON)
Assetic (OSCON)Kris Wallsmith
1.2K vues127 diapositives
Jqueryforbeginnersjqueryconference2009 090914063709 Phpapp02 par
Jqueryforbeginnersjqueryconference2009 090914063709 Phpapp02Jqueryforbeginnersjqueryconference2009 090914063709 Phpapp02
Jqueryforbeginnersjqueryconference2009 090914063709 Phpapp02careersblog
1.7K vues73 diapositives
Sequelize par
SequelizeSequelize
SequelizeTarek Raihan
461 vues23 diapositives

Similaire à Canjs(20)

Summit2014 topic 0066 - 10 enhancements that require 10 lines of code par Angel Borroy López
Summit2014 topic 0066 - 10 enhancements that require 10 lines of codeSummit2014 topic 0066 - 10 enhancements that require 10 lines of code
Summit2014 topic 0066 - 10 enhancements that require 10 lines of code
Javascript first-class citizenery par toddbr
Javascript first-class citizeneryJavascript first-class citizenery
Javascript first-class citizenery
toddbr1.2K vues
Jqueryforbeginnersjqueryconference2009 090914063709 Phpapp02 par careersblog
Jqueryforbeginnersjqueryconference2009 090914063709 Phpapp02Jqueryforbeginnersjqueryconference2009 090914063709 Phpapp02
Jqueryforbeginnersjqueryconference2009 090914063709 Phpapp02
careersblog1.7K vues
BP-6 Repository Customization Best Practices par Alfresco Software
BP-6 Repository Customization Best PracticesBP-6 Repository Customization Best Practices
BP-6 Repository Customization Best Practices
Alfresco Software1.2K vues
[Coscup 2012] JavascriptMVC par Alive Kuo
[Coscup 2012] JavascriptMVC[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC
Alive Kuo1.3K vues
jQuery Anti-Patterns for Performance & Compression par Paul Irish
jQuery Anti-Patterns for Performance & CompressionjQuery Anti-Patterns for Performance & Compression
jQuery Anti-Patterns for Performance & Compression
Paul Irish25.2K vues
Introducing Assetic: Asset Management for PHP 5.3 par Kris Wallsmith
Introducing Assetic: Asset Management for PHP 5.3Introducing Assetic: Asset Management for PHP 5.3
Introducing Assetic: Asset Management for PHP 5.3
Kris Wallsmith33.7K vues
Practical HTML5: Using It Today par Doris Chen
Practical HTML5: Using It TodayPractical HTML5: Using It Today
Practical HTML5: Using It Today
Doris Chen972 vues
Building a real life application in node js par fakedarren
Building a real life application in node jsBuilding a real life application in node js
Building a real life application in node js
fakedarren20.4K vues
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group) par Doris Chen
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
Doris Chen9.5K vues
Beyond DOMReady: Ultra High-Performance Javascript par aglemann
Beyond DOMReady: Ultra High-Performance JavascriptBeyond DOMReady: Ultra High-Performance Javascript
Beyond DOMReady: Ultra High-Performance Javascript
aglemann2.7K vues

Dernier

Don’t Make A Human Do A Robot’s Job! : 6 Reasons Why AI Will Save Us & Not De... par
Don’t Make A Human Do A Robot’s Job! : 6 Reasons Why AI Will Save Us & Not De...Don’t Make A Human Do A Robot’s Job! : 6 Reasons Why AI Will Save Us & Not De...
Don’t Make A Human Do A Robot’s Job! : 6 Reasons Why AI Will Save Us & Not De...Moses Kemibaro
35 vues38 diapositives
"Package management in monorepos", Zoltan Kochan par
"Package management in monorepos", Zoltan Kochan"Package management in monorepos", Zoltan Kochan
"Package management in monorepos", Zoltan KochanFwdays
34 vues18 diapositives
State of the Union - Rohit Yadav - Apache CloudStack par
State of the Union - Rohit Yadav - Apache CloudStackState of the Union - Rohit Yadav - Apache CloudStack
State of the Union - Rohit Yadav - Apache CloudStackShapeBlue
303 vues53 diapositives
MVP and prioritization.pdf par
MVP and prioritization.pdfMVP and prioritization.pdf
MVP and prioritization.pdfrahuldharwal141
39 vues8 diapositives
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit... par
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...ShapeBlue
162 vues25 diapositives
Future of Indian ConsumerTech par
Future of Indian ConsumerTechFuture of Indian ConsumerTech
Future of Indian ConsumerTechKapil Khandelwal (KK)
36 vues68 diapositives

Dernier(20)

Don’t Make A Human Do A Robot’s Job! : 6 Reasons Why AI Will Save Us & Not De... par Moses Kemibaro
Don’t Make A Human Do A Robot’s Job! : 6 Reasons Why AI Will Save Us & Not De...Don’t Make A Human Do A Robot’s Job! : 6 Reasons Why AI Will Save Us & Not De...
Don’t Make A Human Do A Robot’s Job! : 6 Reasons Why AI Will Save Us & Not De...
Moses Kemibaro35 vues
"Package management in monorepos", Zoltan Kochan par Fwdays
"Package management in monorepos", Zoltan Kochan"Package management in monorepos", Zoltan Kochan
"Package management in monorepos", Zoltan Kochan
Fwdays34 vues
State of the Union - Rohit Yadav - Apache CloudStack par ShapeBlue
State of the Union - Rohit Yadav - Apache CloudStackState of the Union - Rohit Yadav - Apache CloudStack
State of the Union - Rohit Yadav - Apache CloudStack
ShapeBlue303 vues
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit... par ShapeBlue
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...
ShapeBlue162 vues
KVM Security Groups Under the Hood - Wido den Hollander - Your.Online par ShapeBlue
KVM Security Groups Under the Hood - Wido den Hollander - Your.OnlineKVM Security Groups Under the Hood - Wido den Hollander - Your.Online
KVM Security Groups Under the Hood - Wido den Hollander - Your.Online
ShapeBlue225 vues
Future of AR - Facebook Presentation par Rob McCarty
Future of AR - Facebook PresentationFuture of AR - Facebook Presentation
Future of AR - Facebook Presentation
Rob McCarty65 vues
DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti... par ShapeBlue
DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti...DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti...
DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti...
ShapeBlue141 vues
"Surviving highload with Node.js", Andrii Shumada par Fwdays
"Surviving highload with Node.js", Andrii Shumada "Surviving highload with Node.js", Andrii Shumada
"Surviving highload with Node.js", Andrii Shumada
Fwdays58 vues
Enabling DPU Hardware Accelerators in XCP-ng Cloud Platform Environment - And... par ShapeBlue
Enabling DPU Hardware Accelerators in XCP-ng Cloud Platform Environment - And...Enabling DPU Hardware Accelerators in XCP-ng Cloud Platform Environment - And...
Enabling DPU Hardware Accelerators in XCP-ng Cloud Platform Environment - And...
ShapeBlue108 vues
Webinar : Desperately Seeking Transformation - Part 2: Insights from leading... par The Digital Insurer
Webinar : Desperately Seeking Transformation - Part 2:  Insights from leading...Webinar : Desperately Seeking Transformation - Part 2:  Insights from leading...
Webinar : Desperately Seeking Transformation - Part 2: Insights from leading...
What’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlue par ShapeBlue
What’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlueWhat’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlue
What’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlue
ShapeBlue265 vues
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue par ShapeBlue
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlueCloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue
ShapeBlue139 vues
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue par ShapeBlue
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlueElevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue
ShapeBlue224 vues
The Role of Patterns in the Era of Large Language Models par Yunyao Li
The Role of Patterns in the Era of Large Language ModelsThe Role of Patterns in the Era of Large Language Models
The Role of Patterns in the Era of Large Language Models
Yunyao Li91 vues

Canjs

  • 2. Why? • Prevents Leaks • Ease of Use • Fast
  • 3. What’s Inside • can.Construct • can.Observe • can.Model • can.Control • can.view • can.EJS • can.route
  • 4. can.Construct(static, proto) var Person = can.Construct({ init : function (name) { this.name = name; } }); var curtis = new Person("Curtis"); curtis.name
  • 5. new can.Observe(data) var person = new can.Observe({ name: 'josh'}); person.bind('name‟, function(ev,newVal,oldVal){ newVal //-> 'Josh Dean' oldVal //-> 'josh' }); person.attr('name') //-> 'josh' person.name //-> 'josh' person.attr('name','Josh Dean‟);
  • 6. can.Model(ajax,proto) var Todo = can.Model({ findAll : '/todo', findOne : '/todo/{id}', destroy : 'POST /todo/destroy/{id}', update : 'POST /todo/{id}', create : '/todo' },{}); Todo.findOne({id: 5}, function( todo ) { todo.attr('name') });
  • 7. can.Control(proto) var Tabs = can.Control({ init: function( el ) { // show first tab }, 'li click': function( el, ev ) { // hide other tabs // show selected tab } }); new Tabs('#tabs');
  • 8. can.route(route, defaults) var Routing = can.Control({ ':type/:id route': function( data ) { } }) new Routing( document.body ); can.route.attr( { type : 'todos', id: 5 } )
  • 9. can.view( idOrURL, data ) -> fragment <script type='text/ejs' id='messageEJS'> <h1><%= message %></h1> </script> can.view('messageEJS', { message : 'Hello World' }) //-> frag <h1>Hello World</h1>
  • 10. EmbeddedJS Templates Favorite tag is <%= ‟<blink>Blink</blink>‟ %> -> My favorite tag is <blink>Blink</blink> Favorite tag is <%== ‟<blink>Blink</blink>‟ %> -> Favorite tag is Blink
  • 11. EmbeddedJS Templates <% if( devs ) { %> <% for( var i = 0; i < devs.length; i++ ) { %> <li><%= arr[i] %></li> <% } %> <% } else { %> <li>No Developers</li> <% } %> can.view('devs.ejs',{devs: ['Andy','Fred']}) //-> frag <li>Andy</li><li>Fred</li>
  • 12. EJS Live Binding <% if( devs.attr('length') ) { %> <% list(devs, function(dev){ %> <li><%= dev.attr(„name‟) %></li> <% }) %> <% } else { %> <li>No Developers</li> <% } %> var devs = new can.Observe.List([ {name : 'Andy'}, {name : 'Fred'} ]) can.view('devs.ejs',{devs : devs}) //-> frag <li>Andy</li><li>Fred</li>
  • 13. Why? • Prevents Leaks • Speed • Flexibility + Libraries • Ease of Use • Features vs Size
  • 14. A tooltip. Undo $('#undo').bind('mouseenter',function(){ $('<div>Undo</div>').tooltipFor(this) })
  • 15. What’s Wrong? $.fn.tooltipFor = function(anchor){ var $el = this .appendTo(document.body) .offset( $(anchor).offset() ) $(anchor).bind('mouseleave',function(ev){ $el.remove() }) }
  • 16. Leaks
  • 18. Templated Events var Tooltip = can.Control({ init: function( el, options ) { el.appendTo(document.body) .offset( $(options.anchor).offset() ) }, '{anchor} mouseleave': function( el, ev ) { this.element.remove(); } }); new Tooltip($('<div>Undo</div>'),{ anchor : this });
  • 19. Non-leaking Global Store Critical Due Today File Taxes Brush Teeth Write talk on CanJS Write talk on CanJS Emissions Test Check into flight
  • 20. Non-leaking Global Store Awesome Developers
  • 22. Plugins • Validations • Getter / Setter • Serialize / Deserialize • Backup / Restore • Super • Proxy $(“#todos”).html( „todos.ejs‟, Todo.findAll() )
  • 23. can.Control and Backbone.View http://jsperf.com/tabs-timing-test
  • 24. Live Binding http://jsfiddle.net/JMWf4/5/
  • 25. Live Binding *can.zepto.js, angular/ember not tested, ask me why http://jsperf.com/canjs-ejs-live-bind
  • 26. Features vs Size CanJS 8.49kb - jQuery Backbone 8.97kb -jQuery +Underscore Knockout 13kb none Batman 15kb -pollyfills for ES5 none Angular 24kb -jQuery Ember 39kb +metamorph.js
  • 28. Questions? safer faster easier smaller library-er http://canjs.us @canjsus

Notes de l'éditeur

  1. Hello, I&apos;m Justin Meyer from BitoviI&apos;m very proud that this is the second time Bitovi (formerly Jupiter) has sponsered JSConfThis year it comes at an important time for us. Not only are we announcing the rebranding at this conference (we are Bitovi now), we are releasing thenext version of JavaScriptMVC&apos;s MVC parts called CanJS.In this talk, I&apos;ll introduce what&apos;s inside CanJS and talk about why, despite a lot of great existing MVC libraries, we think CanJS is the best one the market.
  2. It will fix the memory leaks that you probably don’t even know you have.Fastest control initialization and live template binding. Your app will start fast and run fast.And it’s super easy to pick up, we documented the hello out of it.
  3. positivity
  4. A basic constructor function helper. Useful for providing inheritance. All of JMVC’s constructors inherit from it.
  5. A basic constructor function helper. Useful for providing inheritance
  6. A basic constructor function helper. Useful for providing inheritance hooks up observes to your back end with declarative service bindings
  7. A basic constructor function helper. Useful for providing inheritance
  8. A basic constructor function helper. Useful for providing inheritance - A special observe that is cross bound to the route - pretty urls
  9. ----- Meeting Notes (4/3/12 00:38) -----embedded js
  10. show changing the obseveralph giving the talk
  11. Leaking Event HandlersCleaning Data Stores
  12. Impossible to create memory leaksPeople don&apos;t know what they are doingCan see it in something as simple as a tool tip where you mouseover the elementand it shows the tooltip widget.You might use this tooltip widget like the following: listen on an anchor element, create the content for the tooltip call tooltipFor with the anchor
  13. can.Control fixes this with templated event handlersYou can bind events that will always be unbound auto-magically
  14. ----- Meeting Notes (4/3/12 00:38) -----cleaned up
  15. The next way CanJS helps with memory is through it’s non-leaking global store. Say we have 2 Todo lists, Critical Todos and today’s todos. These lists might get back data for the same instance of a todo. The problem happens when a user changes properties on a todo that exists in both lists. Both lists need to be listening to property changes on the same todo instance.Model needs to see that the data it retrieves belongs to the same instance and return the previously created instance instead of creating a new one.Most MVC libraries either ignore it or solve it with a model store that has all instances, when data is retrieved for an instance, it checks if the instance is already created and uses that instance instead of creating a new one.The problem with this is for long-lived applications, you are constantly collecting unused instances, which fills memory. The developer has to tell the store when to flush instances.CanJS solves this by keeping things in the store only when it knows you are interested in them. How do you express interest? Well by binding to the instance. So, Model keeps instances in the store only while they have event handlers.This, combined with templated event handling, means that simply by replacing the todo list ELEMENTs with a list of “Awesome Developers”&lt;li class=“&lt;%= todo.attr(‘complete’) ? “done” :”” %&gt;” &gt;Very common, but tricky and critical problem for MVC.CanJS has a non-leaking global store, that allows it to solve the 2 ‘instance’ problem without permanently storing all model instances.
  16. All controls are torn down, when all controls are torn down, all event handlers are unbound. When an model instances event handlers are unbound, it’s removed from the store.If you don’t understand this, that’s ok … the big take away is that it’s pretty much impossible to make a leaking CanJS app … You bind and forget ….
  17. Set out to make CanJS the best documented library.Awesome overview page with it’s sweet navigation, underlying docs for every function, method, attribute, and demo applications for each component.Annotated SourceAnd hire us for training, support, or development
  18. deep bindingthe flexibility to switch between libraries without losing all your skills and even some of your (code)
  19. Hello, I&apos;m Justin Meyer from BitoviI&apos;m very proud that this is the second time Bitovi (formerly Jupiter) has sponsered JSConfThis year it comes at an important time for us. Not only are we announcing the rebranding at this conference (we are Bitovi now), we are releasing thenext version of JavaScriptMVC&apos;s MVC parts called CanJS.In this talk, I&apos;ll introduce what&apos;s inside CanJS and talk about why, despite a lot of strong competition, we think CanJS is the best MVC library on the market.