Last active
December 10, 2015 13:08
-
-
Save isochronous/4439430 to your computer and use it in GitHub Desktop.
register a region with a marionette sub-app after root app instantiation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This code assumes you start all your sub-apps during the root-app's init | |
// phase. If not, this same logic can be bound to a different event (ex. start). | |
rootApp.on("initialize:after", function () { | |
vent.trigger("system:default:region:set", rootApp.body); | |
}); | |
// Then in some other sub-application | |
define([ | |
'marionette', | |
'mysupervent' | |
], function(Marionette, vent){ | |
var someApp = new Marionette.Application(); | |
var regDefaultRegion = function(reg) { | |
someApp.defaultRegion = reg; | |
}; | |
// As long as this someApp has been initialized when the event above is | |
// triggered, then rootApp.body will be passed as `reg` to the | |
// regDefaultRegion method above. | |
someApp.addInitializer(function(options) { | |
vent.bindTo(vent, "system:default:region:set", regDefaultRegion, this); | |
}); | |
// As long as the component in question uses the same instance of supervent, | |
// you can now get and use this region from any piece of your application by | |
// doing `var mainReg = vent.reqres.request("app:request:region:default");` | |
vent.reqres.addHandler("app:request:region:default", function(){ | |
return someApp.defaultRegion; | |
}); | |
someApp.start(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment