Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Marionette Controller Best Practice

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?

like image 515
Donald J Avatar asked Mar 09 '15 13:03

Donald J


1 Answers

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
    });
like image 170
joconja Avatar answered Oct 13 '22 17:10

joconja