lundi 25 mai 2015

(Ember.js) How to Share Model Data Among Unrelated Resources/Routes?

What is the best way (the Ember way) to share model data among resources/routes that don't share a parent resource/route?

Details:

I have 2 top level resources (resource1 and resource2) whose model hooks retrieve almost the same data via Ajax, so their model hook code look almost the same as well, i.e. not very DRY. The difference is what they each do with that data.

The Goal: Keep resource1 and resource2 top level resources (or at least have their URLs look like they're top level resources), have them share some model data without duplicating model hook code.

Resource/Route definitions:

App.Router.map(function () {
    ...
    this.resource("resource1", function () {
        this.route("routeA");
        this.route("routeB");
    });
    this.resource("resource2", function () {
        this.route("routeA");
        this.route("routeB");
    });
    ...
}  

Desired URL's:

http://ift.tt/1HGOhOV
http://ift.tt/1Fc5gCG

http://ift.tt/1HGOhOX
http://ift.tt/1Fc5gCK  

NOT [nested within a common resource] like this:

http://ift.tt/1HGOhP0...
http://ift.tt/1Fc5gCO...

Thanks in advance!




Aucun commentaire:

Enregistrer un commentaire