Reputation: 7181
I'm trying to extend marionette's module class in coffeescript, using a commonJS pattern, so that I can require a general Module class to reuse across parts of my app. So far, no luck.
So far I've tried this:
module.exports = class SingleFeed extends Marionette.Module
@addInitializer((options) =>
console.log 'initialize'
)
and this:
module.exports = Marionette.Module.extend(
@addInitializer((options) =>
console.log 'initialize'
)
)
With the hope that I could reuse this code in my application like this:
HomeFeed = require '../modules/components/feeds/SingleFeed'
hf = new HomeFeed()
app.module('HomeFeed',
moduleClass: hf
).start(options)
Has anyone successfully done this with coffeescript? Or does anyone have any ideas that might help?
Here's the documentation I'm referencing: https://github.com/marionettejs/backbone.marionette/blob/master/docs/marionette.application.module.md
Upvotes: 1
Views: 642
Reputation: 1018
The problem that addInitializer
is method of module instance but when you extended you can't call it. But you can override empty default initialize
where you can add your initializers and finalizers like that:
module.exports = Marionette.Module.extend(
initialize: () ->
console.log('initialize module')
@addInitializer((options) =>
console.log 'starting module'
)
)
Upvotes: 1