Circular Dependencies for a web app using backbone.marionette and requireJs

后端 未结 3 1938
北恋
北恋 2021-02-15 13:49

I am in the following situation.

I am using requireJs to loads module and I don\'t want to use global variables.

The main.js is responsible to load the router.

3条回答
  •  隐瞒了意图╮
    2021-02-15 14:34

    the schema:

     main.js -> router -> app -> subApp -> router
    

    is right.

    If you are using backbone.marionette, in order to access the router from the app and subApp, without using global var, you should start the app in router in this way:


    // router.js
    YourApp.start(router: router);
    

    // app.js
    YourApp.addInitializer(function(options){
      // do useful stuff here
      var myView = new MyView({
        router: options.router
      });
      YourApp.mainRegion.show(myView);
    });
    

提交回复
热议问题