Marionette Controller Best Practice
Asked Answered
U

1

7

According to the v2.4.1 Marionette documentation controllers are being deprecated:

Warning: deprecated. The Controller object is deprecated. Instead of using the Controller class with the AppRouter, you should specify your callbacks on a plain Javascript object.

I'm confused as to what the best practices are now that they are deprecated? Does this mean that the AppRouter is also being deprecated? If so what are the current patterns being used to develop large scale Marionette applications?

Undistinguished answered 9/3, 2015 at 13:46 Comment(1)
github.com/davidsulc/marionette-gentle-introduction/blob/master/… or good answer from danikoren in #11410559Bellringer
P
7

You can probably just use Marionette.Object. It's basically the same as the Controller.

To use a plain JavaScript object with the AppRouter you could do something like this:

    var MyController = Marionette.Object.extend({/*...*/});
    var AnotherController = Marionette.Object.extend({/*...*/});

    var myController = new MyController();
    var anotherController = new AnotherController();

    var plainJsObject = {
      doStuff: myController.doStuff,
      doSomethingDifferent: anotherController.doSomethingDifferent
    };

    var router = Marionette.AppRouter.extend({
      controller: plainJsObject
    });
Portraitist answered 11/3, 2015 at 6:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.