16. BEST
PRACTICES
MVC Separation
Memory Safety
REST Service Layer
Routing Logic in Controller
17. BEST PRACTICES
Model - View - Controller
can.Construct can.Control can.view
can.Observe can.route can.EJS
can.Model
18. BEST PRACTICES
can.Model
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')
});
19. BEST PRACTICES
can.Model and can.Observe
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’);
20. BEST PRACTICES
can.Control
var Tabs = can.Control({
init: function( el ) {
// show first tab
},
'li click': function( el, ev ) {
// hide other tabs
// show selected tab
}
});
new Tabs('#tabs');
28. BEST PRACTICES
can.Control and 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
});
58. PRODUCTIVITY
Partial Views
<% for( var i = 0; i < todos.length; i++ ) { %>
<li><%== can.view.render( '/todos/todo.ejs', {
todo: todo[ i ]
} ) %>
</li>
<% } %>
59. PRODUCTIVITY
can.compute
var project = new can.Observe({
progress: 0.5
});
var computed = can.compute(function(val){
if(val) {
project.attr('progress', val / 100);
} else {
return project.attr('progress') * 100;
}
});
new Slider({val : computed});
Hinweis der Redaktion
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
Set out to make CanJS the best documented library.\n\nAwesome overview page with it&#x2019;s sweet navigation, underlying docs for every function, method, attribute, and demo applications for each component.\n\nAnnotated Source\n\n\nAnd hire us for training, support, or development\n
Set out to make CanJS the best documented library.\n\nAwesome overview page with it&#x2019;s sweet navigation, underlying docs for every function, method, attribute, and demo applications for each component.\n\nAnnotated Source\n\n\nAnd hire us for training, support, or development\n
Set out to make CanJS the best documented library.\n\nAwesome overview page with it&#x2019;s sweet navigation, underlying docs for every function, method, attribute, and demo applications for each component.\n\nAnnotated Source\n\n\nAnd hire us for training, support, or development\n
Set out to make CanJS the best documented library.\n\nAwesome overview page with it&#x2019;s sweet navigation, underlying docs for every function, method, attribute, and demo applications for each component.\n\nAnnotated Source\n\n\nAnd hire us for training, support, or development\n
Set out to make CanJS the best documented library.\n\nAwesome overview page with it&#x2019;s sweet navigation, underlying docs for every function, method, attribute, and demo applications for each component.\n\nAnnotated Source\n\n\nAnd hire us for training, support, or development\n
Set out to make CanJS the best documented library.\n\nAwesome overview page with it&#x2019;s sweet navigation, underlying docs for every function, method, attribute, and demo applications for each component.\n\nAnnotated Source\n\n\nAnd hire us for training, support, or development\n
Set out to make CanJS the best documented library.\n\nAwesome overview page with it&#x2019;s sweet navigation, underlying docs for every function, method, attribute, and demo applications for each component.\n\nAnnotated Source\n\n\nAnd hire us for training, support, or development\n
Set out to make CanJS the best documented library.\n\nAwesome overview page with it&#x2019;s sweet navigation, underlying docs for every function, method, attribute, and demo applications for each component.\n\nAnnotated Source\n\n\nAnd hire us for training, support, or development\n
Set out to make CanJS the best documented library.\n\nAwesome overview page with it&#x2019;s sweet navigation, underlying docs for every function, method, attribute, and demo applications for each component.\n\nAnnotated Source\n\n\nAnd hire us for training, support, or development\n
Set out to make CanJS the best documented library.\n\nAwesome overview page with it&#x2019;s sweet navigation, underlying docs for every function, method, attribute, and demo applications for each component.\n\nAnnotated Source\n\n\nAnd hire us for training, support, or development\n
Set out to make CanJS the best documented library.\n\nAwesome overview page with it&#x2019;s sweet navigation, underlying docs for every function, method, attribute, and demo applications for each component.\n\nAnnotated Source\n\n\nAnd hire us for training, support, or development\n
Set out to make CanJS the best documented library.\n\nAwesome overview page with it&#x2019;s sweet navigation, underlying docs for every function, method, attribute, and demo applications for each component.\n\nAnnotated Source\n\n\nAnd hire us for training, support, or development\n
Set out to make CanJS the best documented library.\n\nAwesome overview page with it&#x2019;s sweet navigation, underlying docs for every function, method, attribute, and demo applications for each component.\n\nAnnotated Source\n\n\nAnd hire us for training, support, or development\n
Set out to make CanJS the best documented library.\n\nAwesome overview page with it&#x2019;s sweet navigation, underlying docs for every function, method, attribute, and demo applications for each component.\n\nAnnotated Source\n\n\nAnd hire us for training, support, or development\n
Set out to make CanJS the best documented library.\n\nAwesome overview page with it&#x2019;s sweet navigation, underlying docs for every function, method, attribute, and demo applications for each component.\n\nAnnotated Source\n\n\nAnd hire us for training, support, or development\n
deep binding\n\n\n\nthe flexibility to switch between libraries without losing all your skills and even some of your (code)\n