Skip to content

Instantly share code, notes, and snippets.

@alecperkins
Created August 15, 2012 20:16
Show Gist options
  • Save alecperkins/3363229 to your computer and use it in GitHub Desktop.
Save alecperkins/3363229 to your computer and use it in GitHub Desktop.
CoffeeScript export helper
window._export = (module, to_export...) ->
for cls in to_export
module[cls.name] = cls
# Usage:
# Export globally:
_export window,
MyModel
MyItemView
MyCollection
MyListView
# Export to a Marionette module
MyApp.module 'AppModule', (AppModule) ->
_export AppModule,
MyModel
MyItemView
MyCollection
MyListView
# Assuming the main Marionette.Application is called window.App
window._exportToModule = (module_name, callback, classes...) ->
App.module module_name, (module, args...) ->
_export(module, classes...)
callback?(module, args...)
# Usage:
runAppModule = (module, app) ->
app.vent.on('app:initialized', runMyModule)
_exportToModule 'AppModule', runAppModule,
MyModel
MyItemView
MyCollection
MyListView
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment