Problem.
I have a set of modules that need to share the same collections.
Collections must be ready before launching the modules.
I'm not sure how to solve this in the cleanest way, and I understand that this may differ from project to project, but here are some thoughts.
Download collections before launch.
This is the first thing that comes to my mind, just download the collection just before I call "App.start ()".
Then I can just make it available in a global area (not sure if I like it.).
Delay in starting submodules before loading.
If I structure the application, so it has a main module that is responsible for launching all submodules.
Then I could preload all the vital data and make sure it was ready before running any auxiliary modules.
Then, perhaps make it available through the core modules API.
I donβt know if this is bad, sin my experience with a puppet is limited.
How am I doing it now.
Atm I decided to download the collection to "App.start ()", this made sins reasonable I also preloaded my templates.
I introduced a "static" object called "CollectionManager" that acts as a proxy / access point for my collections. And will be available worldwide.
Application Setup:
var arrTemplatesPaths = [...];
var arrSharedCollections = [
{id:"groups", collection: GroupCollection}
];
$.when.apply(null, [
Templates.fetch(arrTemplatesPaths),
CollectionManager.fetch(arrSharedCollections)
])
.then(function(){
App.start();
})
Access:
Then modules that need access to the collection can simply call CollectionManager.get (id)
var collection = CollectionManager.get("groups");
This provides some structure, but I'm not sure I like it.
Update
, Marionette Marionette.RequestResponse.
,
, .
, :
App.reqres.addHandler("getCollection", function (id) {
return CollectionManager.get(id);
})
:
var collection = App.request("getCollection", "groups")
, CollectionManager .