Created
August 15, 2012 20:16
-
-
Save alecperkins/3363229 to your computer and use it in GitHub Desktop.
CoffeeScript export helper
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
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 |
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
# 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