While building a large marionette app I came across an issue that I was continually trying to solve.
I have multiple apps which generally have one high level controller to manage everything within. I have public methods which allow the loading of a specific sub module into a sub apps region. However, when I use a Route to hit this method I generally find that the layout has not been 'shown'.
MyApp.Controller = Marionette.Controllers.extend({
initialize: function (options) {
this.region = options.region;
this.layout = this._getLayout();
},
showSomething: function () {
// Layout may not be rendered at this point if I hit it with a Route
this.getMyView();
},
_getLayout: function () {
var layout = new MyLayout.Layout();
this.region.show(layout);
return layout;
}
});
App.addInitializer(function () {
App.MyApp.controller = new MyApp.Controller({
region: App.theMainRegion
});
});
Router = new Backbone.Router.extend({
routes: {
'showSomething':'showSomething'
},
showSomething: function () {
App.MyApp.start();
App.MyApp.controller.showSomething();
}
});
I have found that I am checking to see if the layout has been 'rendered' and putting logic within an if statement. Any suggestions on how I can better approach this problem?
Cheers!