Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
CanJS
Search
sporto
April 11, 2013
Programming
6
630
CanJS
An overview of CanJS and comparison with Backbone, Angular and Ember
sporto
April 11, 2013
Tweet
Share
More Decks by sporto
See All by sporto
React inside Elm
sporto
2
170
Elm
sporto
1
250
Redux: Flux Reduced
sporto
1
330
Practically Immutable
sporto
0
180
Webpack and React
sporto
4
380
Rails with Webpack
sporto
1
210
Lesson learnt building Single Page Application
sporto
0
110
Grunt
sporto
1
160
Safe Testing in Ruby
sporto
1
120
Other Decks in Programming
See All in Programming
PaaSとSaaSの境目で信頼性と開発速度を両立する 〜TROCCO®︎のこれまでとこれから〜
gtnao
6
7.3k
Modular Monolith Monorepo ~シンプルさを保ちながらmonorepoのメリットを最大化する~
yuisakamoto
11
4k
Djangoの開発環境で工夫したこと - pre-commit / DevContainer
hiroki_yod
1
670
17年周年のWebアプリケーションにTanStack Queryを導入する / Implementing TanStack Query in a 17th Anniversary Web Application
saitolume
0
130
Develop iOS apps with Neovim / vimconf_2024
uhooi
1
330
複雑な仕様に立ち向かうアーキテクチャ
myohei
0
130
Jakarta EE meets AI
ivargrimstad
0
990
DevFest Tokyo 2025 - Flutter のアプリアーキテクチャ現在地点
wasabeef
4
640
Discord Bot with AI -for English learners-
xin9le
1
120
romajip: 日本の住所CSVデータを活用した英語住所変換ライブラリを作った話
sangunkang
0
2.4k
SymfonyCon Vienna 2025: Twig, still relevant in 2025?
fabpot
3
980
Seamless Flutter Native Integration: FFI & Pigeon - Dreamwalker (JaichangPark / 박제창) @FlutterKaigi2024
itsmedreamwalker
0
120
Featured
See All Featured
Site-Speed That Sticks
csswizardry
1
160
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
29
2k
YesSQL, Process and Tooling at Scale
rocio
169
14k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
Code Review Best Practice
trishagee
64
17k
Designing for Performance
lara
604
68k
A designer walks into a library…
pauljervisheath
204
24k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
Building Better People: How to give real-time feedback that sticks.
wjessup
365
19k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
GitHub's CSS Performance
jonrohan
1030
460k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
Transcript
Sebastian Porto @sebasporto
•Intro •Features •Demo •Why?
2008 2012 Part of JMVC 3
CAN.JS MVC View Controller events Model m odify updates via
events
FEATURES
OVERVIEW can.Construct can.Observe can.Model can.Control can.view EJS Mustache can.route
can.Construct var Person = can.Construct({ init: function (name) { this.name
= name; } }); var zack = new Person(”Zack");
OBSERVABLES Construct Observable
can.Observe var state = new can.Observe({ selected: null, showSave: false
});
can.Observe state.bind('selected', function (oldVal, newVal) { … }); state.attr(‘selected’, item);
state.attr(‘selected’);
MODELS Construct Observable Model
can.Model var Library = can.Model({ findAll: ‘GET /libraries’, create: 'POST
/libraries', update: 'PUT /libraries/{id}', destroy: 'DELETE /libraries/{id}' }, {});
can.Model new Library.List([]); Collection Member new Library({name: ‘jQuery’});
VIEWS Model Views live bindings
can.view var template = can.view("#template", { libraries: this.libraries, state: this.state
}); can.$(ele).append(template);
EJS <% libs.forEach(function(el, ix) { %> <li><%= el.name %></li> <%
}) %> <% if (state.isEditing) { %> <button>Save</button> <% } %>
Mustache {{#libraries}} <li>{{name}}</li> {{/libraries}} {{#state.isEditing}} <button>Save</button> {{/state.isEditing}}
CONTROLLERS Controller Model View events m odify
can.Control var Control = can.Control({ init: function (ele, options) {
… } }); var control = new Control('#main’, {});
can.Control '.btn_save click': function (ele, ev) { }, '.name keyup':
function (ele, ev) { }
Other Goodies •Validations •Dirty attributes •Fixtures •Handlebars helpers (Transformations, filters)
DEMO
WHY?
None
LEARNING CURVE A subjective comparison
BACKBONE Confused
EMBER “We frequently receive feedback from new developers about how
frustrating it can be to get started with Ember” Yehuda Katz & Tom Dale http://emberjs.com/blog/2013/03/21/making-ember-easier.html
ANGULAR Wow
None
Convenience / Magic Easier to Learn
They way you already know, is most likely the right
way.
ANGULAR function Ctrl($scope, $element) { $(‘.tree’, $element).dynatree({}); }
That’s not the Angular way! You should use directives!
CAN init: function (element, options) { $(‘.tree’, element).dynatree({}); … }
Yay!
SIZE KB (MIN) Ember Angular CanJS Backbone 18 33 80
141
SIZE KB (MIN) Ember + jQuery + Handlebars Angular CanJS
+ Zepto Backbone + _ + Zepto + Mustache 61 57 80 269
INTEGRATION
Memory leak safe '.btn_save click': function (ele, ev) { …
},
Performance http://jsperf.com/angular-vs-knockout-vs-ember/118
Succinct Source http://paulhammant.com/2013/01/18/client-side-mvc-roundup/
TRY IT OUT!
THANKS... QS?
With #canjs you can do 80% of what you can
possibly need with 20% the learning curve of the others. Sebastian Porto @sebasporto
THE REALLY IMPORTANT STUFF Backbone CanJS Angular Ember Easy to
learn ˒ ˒ Great docs ˒ ˒ ˒ Observable Models ˒ ˒ ˒ ˒ Routing ˒ ˒ ˒ ˒ Views with live bindings ˒ ˒ ˒ Two way bindings ˒ ˒ Avoid unnecessary boilerplate ˒ ˒ ˒