Upgrade to Pro — share decks privately, control downloads, hide ads and more …

INtroduction au CanJS javascript MVC framework

INtroduction au CanJS javascript MVC framework

Présentation du conférence qui été dans le cadre de DzWebDayz Ouargla 'Algérie'

More Decks by Mohamed Cherif Bouchelaghem

Other Decks in Programming

Transcript

  1. CanJS is a JavaScript library that makes developing complex applications

    simple and fast. Easy-to-learn, small, and unassuming of your application structure, but with modern features like custom tags and 2-way binding. Creating apps is easy and maintainable.
  2. Caractéristiques can.Contsruct (Constructeurs) can.Control (Controlleurs) can.Map (Objets Observables) can.view (Vue)

    can.Model (Models) can.Component (Composant) can.route (Routage) can.view.ejs (Embeded JS) can.view.mustache (Mustache/Handlebars) can.compute (Valeurs Observables)
  3. new can.Map(data) var person = new can.Map({name:'Cherif'}); person.attr('name') //-> 'Cherif'

    person.bind('name',function(ev,newVal,oldVal){ newVal //-> 'Khaled' oldVal //-> 'Cherif' }); person.attr('name','Khaled');
  4. new can.List(data) var hobbies = new can.List(['JS']); hobbies.attr(0) //-> 'JS'

    hobbies.bind('add',function(ev,items,index){ items //-> ['bball','football'] index //-> 1 }); hobbies.push('bball','football');
  5. can.compute(getter) var info = can.compute(function(){ return person.attr("name")+" a "+age()+ "

    ans et aime: "+hobbies.join(', ') }); info() //-> "Cherif a 31 ans et aime JS, bball, football" info.bind('change',function(ev,newVal,oldVal){ newVal //-> "Cherif a 31 ans et aime JS, bball" }); hobbies.pop();
  6. can.Model.extend(s,p) var Task = can.Model.extend({ findAll: "GET /tasks", findOne: "GET

    /tasks/{id}", create: "POST /tasks", update: "PUT /tasks/{id}", destroy: "DELETE /tasks/{id}" },{}) Task.findAll({due:"today"},function(tasks){}) Task.findOne({id: 51},function(task){});
  7. can.Control.extend( p ) var Tabs = can.Control.extend({ init: function( el,options

    ) { // Afficher le premier onglet }, 'li click': function( el, ev ) { // Masquer les autes onglet // Afficher l'onglet selectioné } }); new Tabs('#tabs');
  8. Mustache / Handlebars {{#if devs.length}} {{#each devs}} <li>{{name}}</li> {{/each}} {{else}}

    <li>pas de développeurs</li> {{/if}} can.view('devs.mustache',{ devs: new can.List([{name:'Khaled'}]) })
  9. EJS <% if( devs.attr('length') ) { %> <% devs.each(function(dev){ %>

    <li><%= dev.attr('name') %></li> <% }) %> <% } else { %> <li>pas de développeurs</li> <% } %> can.view('devs.ejs',{ devs: new can.List([{name:'Khaled'}]) })
  10. can.Component.extend(p) <tabs> {{#each foodTypes}} <panel title='title'> {{content}} </panel> {{/each}} </tabs>

    var foodTypes= new can.List([ {title:"Fruits",content:"oranges"}, …])
  11. 2 way binding var Voyage= can.Map.extend({ voyageTemp:function(){ return this.attr('dist')/110 //km/h

    } }); var alger=new Voyage({ dist:563.67 }); var template=can.view.mustache('<p><lable>distance:</label>\ <input can-value="dist"/></p>\ <p>Temp:{{voyageTemp}}</p>'); $('#vo').html(template(alger));
  12. Faites le à votre maniére <slider min="0" max="100"></slider> new Slider("#progress",{

    min: 0, max: 100 }); $("#progress").slider({ min: 0, max: 100 });
  13. Faites le à votre maniére Task = can.Model.extend({ findAll: "/GET

    /tasks" },{}) Task = can.Model.extend({ findAll: { crossDomain: true, dataType: "jsonp", jsonpCallback: "callback" } },{})
  14. Faites le à votre maniére Task = can.Model.extend({ findAll: "/GET

    /tasks" },{}) Task = can.Model.extend({ findAll: function(params){ var deferred = $.Deferred(); connect(function(data){ deferred.resolve(Task.models(data)) }); return deferred; } },{})
  15. AngularJS Backbone CanJS EmberJS Observables O N O O Routing

    O O O O View Binding O N O O Two way Bindings O N O O Partial views O N O O Filtred List views O N O O Flexibilty N O O N Caratéristiques