Closed gregtap closed 10 years ago
Is there any way to get this to work? It seems to be a problem with the fact that Brunch wraps everything as CommonJs modules, and that breaks Marionette's built in module system.
Any pointers?
Hi Dorian, I could not find a proper way so I just crammed up stuff in one file: https://github.com/novapost/dragndoc/blob/master/app/application.coffee
Okay, I guess that's what I'll have to do for now then. Thanks for the quick reply! Hopefully this is something that'll be fixable in the future?
Hey All,
So maybe I set things up differently than most so I'd love to get your feedback. In this skeletons application.coffee I export an instance of the application. Which means from anywhere you can do `app = require('application') and get the single instance of your application.
https://github.com/SimbCo/brunch-with-marionette/blob/master/app/application.coffee
So I have always kept all my modules in other files and I set them up something like this.
application = require 'application' Layout = require('./views/DataEntryLayout')
module.exports = application.module("DataEntry", ( mod, app, Backbone, Marionette, $, _ )=>
mod.startWithParent = false;
mod.addInitializer( (options) =>
ViewController = require './controllers/ViewController'
MainController = require './controllers/MainController'
mod.viewController = new ViewController()
mod.mainController = new MainController()
mod.layout = new Layout()
mod.layout.render()
# Freeze the object
#Object.freeze? this
)
mod.on("start", =>
mod.viewController.dispatch("load:de_home")
)
mod.on('render', =>
)
mod.on('before:stop', =>
application.model.set("userHasEditedRecord",false)
)
mod.addFinalizer( =>
mod.viewController.stopListening()
mod.mainController.stopListening()
delete mod.viewController
delete mod.mainController
)
)
I have some other stuff in there from a project I call Paddles which decouples the marionette controllers from the routing mechanism. But the point is to show that you can separate your modules right now.
Nice trick, you are right it is possible.
Ok, cool. Let me know if someone thinks of a way to improve this.
It would be very interesting to see how to solve the use of Marionette modules in a separate file than application.coffee in a Brunch context.
https://github.com/marionettejs/backbone.marionette/blob/master/docs/marionette.application.module.md