Adds the concept of small modular appliances to MarionetteJS.
In a simple case where you have a function called require() that can require JavaScript models, you should be able to simply do the following:
class ExampleApplication extends Marionette.ApplianceManager
appliances: [
'example'
]
After loading your application, it will attempt the following process:
-
Call
require("example/controller")
and expect it to export an object calledController
which extendsMarionette.AppRouter
. If a controller is found, it will be instantiated and pass yourApplication
instance as theapplication
option to the controller. This allowsthis.options.application
to refer to the current application instance for every appliance controller.If the Controller does not exist, then the next step will be skipped.
-
Since we have found a
Controller
, attempt torequire("example/router")
and expect this to export an object calledRouter
which extendsMarionette.AppRouter
. If the object exists, it will instantiate the providedRouter
passing the controller instance as thecontroller
option. -
Restart this process with the next appliance until all appliances have been created.
-
Assign all routers to application.routers[applianceName], so that appliances can communicate with eachother via events or function calls if necessary.
This seems very simple, but the structure implied by it provides a set of conventions which make working with large apps very simple.
They solve a different problem. You could use modules along with this if you wanted to nest ApplianceManagers.