Last active
December 21, 2015 07:28
-
-
Save cmcculloh/6270990 to your computer and use it in GitHub Desktop.
Referencing "the app" and venting with Marionettejs...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define(function (require) { | |
//require dependancies | |
var Marionette = require('backbone.marionette'); | |
var Backbone = require('backbone'); | |
var $ = require('jquery'); | |
var _ = require('underscore'); | |
// Override renderer to use pre-compiled templates | |
Marionette.Renderer.render = function (template, data) { | |
return template(data); | |
}; | |
// Create, configure, and return application object | |
var app = new Marionette.Application(); | |
app.addRegions({ | |
mainRegion: '#main' | |
}); | |
app.addInitializer(function (options) { | |
this.router = options.router; | |
this.models = new Backbone.Model(); | |
this.views = new Backbone.Model(); | |
}); | |
app.on('initialize:after', function () { | |
$(function () { | |
Backbone.history.start(); | |
}); | |
}); | |
return app; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define(function (require) { | |
var app = require('app/app'); | |
var MyView = require('views/myView'); | |
app.addInitializer(function () {}); | |
var controller = { | |
showView: function showView(){ | |
app.mainRegion.show(new MyView({ model: new Backbone.Model({'prop':'value'}) })); | |
} | |
} | |
return controller; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define(function (require) { | |
var app = require('app/app'); | |
return Marionette.ItemView.extend({ | |
template: '#MySubView', | |
events: { | |
'click #button': 'sendClick' | |
}, | |
triggers: { | |
'afterClick': 'afterClick' | |
}, | |
initialize: function initialize(){ | |
this.on('afterClick', this.afterClick); | |
}, | |
sendClick: function(e) { | |
e.preventDefault(); | |
console.log('Good... Use your ventful capabilities boy...'); | |
//trigger some method in the parent... | |
this.trigger('processClick'); | |
}, | |
afterClick: function(who) { | |
console.log("I've been waiting for you... The circle is now complete. When I left you I was the but the sender, now I am the receiver...", who); | |
} | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define(function (require) { | |
var app = require('app/app'); | |
var MySubView = require('views/mySubView'); | |
return Marionette.Layout.extend({ | |
template: '#MyView', | |
views: {}, | |
regions: { | |
myRegion: '#myRegion' | |
}, | |
onShow: function onShow(){ | |
this.views.mySubView = new MySubView({ model: this.model }).on('processClick', this.sendBackClick, this); | |
this.myRegion.show(this.views.mySubView); | |
}, | |
sendBackClick: function(){ | |
//do some stuff, then, let the child know you're done... | |
console.log('heh heh heh heh.... Goood, goooood! Your triggers have made you powerful. Now, fulfil your parents destiny and take the event at my side!!!'); | |
//use trigger? | |
this.views.mySubView.trigger('afterClick', 'from trigger'); | |
//call method directly? | |
this.views.mySubView.afterClick('called directly'); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment