Basically, what I'm trying to do is find the best way to manage all my views. So all my views are closed and created when necessary .. And because of this, I created a separate manager inside my Backbone.Router , which performs all my views as follows.
router.js
AppRouter.prototype.initialize = function () { ....... var eMgr = _.extend({}, Backbone.Events); var vMgr = new ViewManager(); vMgr.add(new vTopMenu({eMgr: eMgr})); vMgr.add(new vTooltip({eMgr: eMgr})); app_router.on('route:MainMenu', function () { vMgr.close_all_views(function(){ vMgr.add(new vmainMenu({eMgr: eMgr})); vMgr.render_all_views(); }); }); app_router.on('route:showMap', function () { vMgr.close_all_views(function(){ vMgr.add(new vMapMenu()); vMgr.render_all_views(); }); }); ... }
As you can see, TopMenu views and tooltips are created only once, since I do not expect that it will be necessary to change their contents. And I would also like to avoid spaces while loading views ...
I am not sure if this is a good idea, since all other views are closed and re-initiated as soon as I move from one route to another.
So the question is, are these views created in this way correctly? Or should I always recreate the views when any route starts?
source share