I am using backbone.router and as a normal rule I would want the old routes to run, but in this one application my routes are calling some dynamically injected script that then tries to create a charting widget and the underlying html is not yet loaded. Which means that my canvas getContext can't happen because the element is undefined until I actually load everything.
basically I have the following method assigned to a route
dashboard: function () {
var myView = new contentCollectionView({
collection: collection,
tagName: "div",
className: "dashboard"
});
myView.close();
schill.content.reset();
schill.content.show(myView);
schill.content.on("show", function(view){
callbacks.run();
});
and the following in my initializer
$.when( collection.fetch() ).then( function(){
//We start our router and the history in order to call our functions bound to particular routes
var router = new Router();
Backbone.history.start();
}
);
but when I stop the module, start another module stop that module and then start my first module again the route executes before the collection.fetch, unfortunately the only way I have found to fix it is to set a property on my Marionette.Application, module.isready
then set that false before starting a module, then set it to true in my initializer after the collection is fetched. This seems not exactly smelly to me, but not pristine and sparkling either.
Since backbone does not want to add any way to stop the router, and the arguments seem reasonable until I hit the edge case, then I would like to know how do other people handle this situation?
Thanks,
Bryan Rasmussen