Skip to content

Instantly share code, notes, and snippets.

@bafxyz
Forked from lxyuma/gist:6424131
Last active September 16, 2015 15:33

Revisions

  1. @lxyuma lxyuma revised this gist Sep 7, 2013. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -114,7 +114,7 @@ MyApp.start();
    // commands

    MyApp = new Marionette.Application();
    MyApp.commands.register("foo", function(){
    MyApp.commands.setHandler("foo", function(){
    console.log("FOO HIT");
    });
    MyApp.execute("foo");
    @@ -124,7 +124,7 @@ MyApp.execute("foo");
    // Request/Response

    MyApp = new Marionette.Application();
    MyApp.reqres.register("foo",function(){
    MyApp.reqres.setHandler("foo",function(){
    return "RESPONSE HIT";
    });
    MyApp.request("foo");
  2. @lxyuma lxyuma revised this gist Sep 7, 2013. 1 changed file with 28 additions and 0 deletions.
    28 changes: 28 additions & 0 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -109,3 +109,31 @@ MyApp.addInitializer(function(options){

    MyApp.start();



    // commands

    MyApp = new Marionette.Application();
    MyApp.commands.register("foo", function(){
    console.log("FOO HIT");
    });
    MyApp.execute("foo");



    // Request/Response

    MyApp = new Marionette.Application();
    MyApp.reqres.register("foo",function(){
    return "RESPONSE HIT";
    });
    MyApp.request("foo");


    // Event

    MyApp = new Backbone.Marionette.Application();
    MyApp.vent.on("foo", function(){
    alert("bar");
    });
    MyApp.vent.trigger("foo");
  3. @lxyuma lxyuma revised this gist Sep 7, 2013. 1 changed file with 19 additions and 0 deletions.
    19 changes: 19 additions & 0 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -90,3 +90,22 @@ var MyRouter = new Marionette.AppRouter({
    }
    });




    // Application
    MyApp = new Backbone.Marionette.Application();
    MyApp.addRegions({ mainRegion: "#main-div" });

    MyApp.addInitializer(function(options){
    var myView = new MyView({ model: options.someModel });
    MyApp.mainRegion.show(myView);
    });

    MyApp.addInitializer(function(options){
    new MyAppRouter();
    Backbone.history.start();
    });

    MyApp.start();

  4. @lxyuma lxyuma revised this gist Sep 7, 2013. 1 changed file with 17 additions and 1 deletion.
    18 changes: 17 additions & 1 deletion gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -73,4 +73,20 @@ var layout = new AppLayout();
    layout.render();

    layout.menu.show(new MenuView());
    layout.content.show(new MainContentView());
    layout.content.show(new MainContentView());


    // AppRouter + Controller

    myController = Marionette.Controller.extend({
    doFoo: function(){
    console.log("FOO!");
    }
    });
    var MyRouter = new Marionette.AppRouter({
    controller: myController,
    appRoutes: {
    "foo": "doFoo"
    }
    });

  5. @lxyuma lxyuma revised this gist Sep 7, 2013. 1 changed file with 2 additions and 5 deletions.
    7 changes: 2 additions & 5 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -54,12 +54,9 @@ var GridView = Backbone.Marionette.CompositeView.extend({

    // Region

    MyApp.addRegions({
    mainRegion: "#main"
    });
    var myView = new MyView();
    MyApp.mainRegion.show(myView);
    MyApp.mainRegion.close();
    mainRegion.show(myView);
    mainRegion.close();



  6. @lxyuma lxyuma revised this gist Sep 7, 2013. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -73,4 +73,7 @@ AppLayout = Backbone.Marionette.Layout.extend({
    }
    });
    var layout = new AppLayout();
    layout.render();
    layout.render();

    layout.menu.show(new MenuView());
    layout.content.show(new MainContentView());
  7. @lxyuma lxyuma revised this gist Sep 7, 2013. 1 changed file with 14 additions and 0 deletions.
    14 changes: 14 additions & 0 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -60,3 +60,17 @@ MyApp.addRegions({
    var myView = new MyView();
    MyApp.mainRegion.show(myView);
    MyApp.mainRegion.close();



    // Layout

    AppLayout = Backbone.Marionette.Layout.extend({
    template: "#layout-template",
    regions: {
    menu: "#menu",
    content: "#content"
    }
    });
    var layout = new AppLayout();
    layout.render();
  8. @lxyuma lxyuma revised this gist Sep 7, 2013. 1 changed file with 10 additions and 0 deletions.
    10 changes: 10 additions & 0 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -50,3 +50,13 @@ var GridView = Backbone.Marionette.CompositeView.extend({
    collectionView.$("tbody").append(itemView.el);
    }
    });


    // Region

    MyApp.addRegions({
    mainRegion: "#main"
    });
    var myView = new MyView();
    MyApp.mainRegion.show(myView);
    MyApp.mainRegion.close();
  9. @lxyuma lxyuma revised this gist Sep 7, 2013. 1 changed file with 16 additions and 0 deletions.
    16 changes: 16 additions & 0 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -34,3 +34,19 @@ MenuListView = Marionette.CollectionView.extend({

    var menuList = new MenuListView({collection: menu});
    menuList.render();


    // CompositeView

    var GridRow = Backbone.Marionette.ItemView.extend({
    template: "#row-template",
    tagName: "tr"
    });
    var GridView = Backbone.Marionette.CompositeView.extend({
    tagName: "table",
    template: "#grid-template",
    itemView: GridRow,
    appendHtml: function(collectionView, itemView){
    collectionView.$("tbody").append(itemView.el);
    }
    });
  10. @lxyuma lxyuma revised this gist Sep 7, 2013. 1 changed file with 5 additions and 2 deletions.
    7 changes: 5 additions & 2 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -27,7 +27,10 @@ view.render();

    // Collection View

    menuListView = Marionette.CollectionView.extend({
    MenuListView = Marionette.CollectionView.extend({
    tagName: "ul",
    itemView: MenuItemView
    })
    });

    var menuList = new MenuListView({collection: menu});
    menuList.render();
  11. @lxyuma lxyuma revised this gist Sep 7, 2013. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -23,3 +23,11 @@ MyView = Backbone.Marionette.ItemView.extend({
    });
    var view = new MyView({model: myModel});
    view.render();


    // Collection View

    menuListView = Marionette.CollectionView.extend({
    tagName: "ul",
    itemView: MenuItemView
    })
  12. @lxyuma lxyuma revised this gist Sep 7, 2013. 1 changed file with 2 additions and 9 deletions.
    11 changes: 2 additions & 9 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -3,15 +3,8 @@
    var MyView = Marionette.ItemView.extend({
    template: "my-template-id"
    });
    var view = new View({ model : Dog});
    view.render();







    var myView = new MyView({ model: Dog});
    myView.render();


    // ItemView sample
  13. @lxyuma lxyuma revised this gist Sep 7, 2013. 1 changed file with 16 additions and 0 deletions.
    16 changes: 16 additions & 0 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,19 @@
    // sample

    var MyView = Marionette.ItemView.extend({
    template: "my-template-id"
    });
    var view = new View({ model : Dog});
    view.render();









    // ItemView sample

    MyView = Backbone.Marionette.ItemView.extend({
  14. @lxyuma lxyuma created this gist Sep 3, 2013.
    16 changes: 16 additions & 0 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    // ItemView sample

    MyView = Backbone.Marionette.ItemView.extend({
    template: "#myTemplate",
    ui: {
    "flag" : "#myFlag"
    },
    modelEvents: {
    "change": "modelChanged"
    },
    modelChanged: function() {
    this.ui.flag.html("changed!");
    }
    });
    var view = new MyView({model: myModel});
    view.render();