Backbone Marionette Module is deprecated, what is a good alternative to handling initializers and start events?
Asked Answered
R

1

6

Like my title says, I do see that Marionette Module is now deprecated and we should AMD modules instead using requirejs. That is fine and everything but the modules had a great purpose in handling initializers and the before:start and start events. It allowed me to setup my regions, views, and collections with ease. What is the alternative now for handling this?

Below is an example of code I would use:

define(['core', './views/mainView'], function(core, mainView) {
    var app = core.app;
    app.start();

return core.app.module('Home Page Module', function(Module) {
    Module.addInitializer(function() {
        this.region = new core.Marionette.Region({
            el: '#page-container'
        });
        this.collection = [];
    });

    Module.on('start', function() {
        this.view = new mainView({
            collection: this.collection
        });
        this.region.show(this.view);
    });
});
});
Reverence answered 17/6, 2015 at 20:41 Comment(1)
Have you considered using var HomePageModule = new Marionette.Application({}); module.exports = HomePageModule;? I haven't really looked into the implications of this, but this seems to achieve some of what you want but maybe with more extra sauce than you really need.Mormon
P
2

I don't have the answer, but Derick Bailey, creator of Marionette, has.

The problem with no sub-applications to start / stop has not yet presented itself in my apps. I don’t need that right now. I know I will need it, though, and when I do run in to that requirement again, I’ll find another solution for it. There’s a good chance I’ll build an add-on for Marionette that specifically works with this new setup, in order to provide the functionality I want.

found here : http://derickbailey.com/2014/06/10/browserify-my-new-choice-for-modules-in-a-browser-backbone-app/

The quote is a little outdated now (one years old), but consider that the feature was deprecated anyway, without any replacement proposal.

Panayiotis answered 18/8, 2015 at 14:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.