1
votes

we are currently working on a big project in Marionette. We've based the architecture on http://www.backbonerails.com/. The project is divided in number of modules , every with its own responsibilities. It's important for the modules to be reusable, so they can be rendered in any region on the website. Right now the modules are initiated like this:

App.execute "module:name_of_the_module:action", @model, @layout.regionName

This worked good so far, but now we added Routers to the project. Every module should have responsibility for their routing, so they are in the modules. Now when the routers get the route and start routing, they are missing the region and model to work with. So we first have to save the region and models to the module to be used in the router later.

App.commands.setHandler "module:name_of_the_module:action", (model, region) ->
       MyModule.region = region
       MyModule.model = model

This is not really a good way to do it, because there is usually many actions on every widget (show, edit, create, ...) and we would have to duplicate a lot.

So I am asking - how do you initialize your modules and work with the routers? Is there some best practice?

1

1 Answers

0
votes

I've create a marionette.js plugin which allows you do state based routing(much like angular.js ui-router). You can completely eliminate modules in code and reuse controllers.

Link: http://ajency.github.io/marionette.state/