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

Backbone & Marionette avec @xbourguignon à Soft...

Backbone & Marionette avec @xbourguignon à SoftShake

Philippe CHARRIERE

October 24, 2013
Tweet

More Decks by Philippe CHARRIERE

Other Decks in Programming

Transcript

  1. klass var TinyToon = Kind.extend({ constructor : function (firstName, lastName){

    this.firstName = firstName; this.lastName = lastName; }, toString : function() { return this.firstName + " " +this.lastName } }); var babs = new TinyToon("Babs", "Bunny")
  2. héritage var Elmyra = TinyToon.extend({ constructor : function (){ this.firstName

    = "Elmyra"; this.lastName = "Duff"; Elmyra.__super__.constructor.call(this); console.log("Oh, it's so cute ♥ ♥ ♥"); }, isChasing : function(toon) { //foo } });
  3. static var Elmyra = TinyToon.extend({ //instance members },{ //statics members

    theOnlyOne : null, getInstance : function() { if(Elmyra.theOnlyOne == null) { Elmyra.theOnlyOne = new Elmyra(); } return Elmyra.theOnlyOne; } }); var elmyra = Elmyra.getInstance();
  4. var Player = Backbone.Model.extend({ urlRoot:"/players" }); var bob = new

    Player({ firstName : "Bob", lastName : "Morane" }) Model
  5. <ol> <% _.each(players, function(player) { %> <li id="<%= player.id %>">

    <%= player.firstName %> <%= player.lastName %> </li> <% }); %> </ol> Avec Underscore template
  6. var PlayersView = Backbone.View.extend({ el : "#players", initialize : function()

    { this.template = _.template($("#template").html()); }, render : function() { this.$el.html( this.template({ players:this.collection.toJSON() }) ); } });
  7. var PlayersView = Backbone.View.extend({ /*...*/ events:{ "click :checkbox" : function(event)

    {}, "click .btn-success" : function() {} } }); var playersView = new PlayersView({collection:players})
  8. var router = Backbone.Router.extend({ routes: { "home": "index", "products/:computer": "display",

    "products/:computer/:model": "display" }, index: function() { }, display: function(computer, model) { } });
  9. Vue

  10. \o/

  11. var mainRegion = new Marionette.Region({ el:"#main-container" }); var view =

    new MyView(); mainRegion.show(view); var otherView = new AnotherView(); mainRegion.show(otherView);
  12. var itemView = new MyView({model: someModel}); itemView.render(); var collectionView =

    newOtherView({ collection: someCollection }); collectionView.render(); automatic render
  13. (function(global) { var MyApp = new Marionette.Application(); MyApp.addRegions({ mainRegion:"#main" });

    MyApp.on("initialize.after", function() { Backbone.history.start(); }) global.MyApp = MyApp; })(window)
  14. MyApp.module("myModule", function(Mod, App, BB, Marionette, $, ...) { var SomeModel

    = Backbone.Model.extend({...}); var ItemView = Marionette.ItemView.extend ({...}); var model = new SomeModel(); ...