Question

I got a Mediator-Sandbox library and a Router extension built on top of this library.

The library is built up like this:

(function(window) {

  var MedSan = {};

  window.MedSan = MedSan;

})(this);

The extension looks like this:

(function(_, Backbone, MedSan) {

  MedSan.Router = {};

})(_, Backbone, MedSan);

The requires config to load the extension looks like this:

require.config({

    baseUrl: "javascripts",

    shim: {
        "jquery": {
            exports: "$"
        },
        "underscore": {
            exports: "_"
        },
        "backbone": {
            deps: ['jquery', 'underscore'],
            exports: "Backbone"
        },
        "Distribution": {
            exports: "Distribution"
        },
        "Distribution.Router": {
            deps: ['underscore', 'backbone', 'Distribution'],
            exports: "Distribution"
        }
    },

    /*
    map: {
        "*": {
            "Distribution": "Distribution.Router"
        }         
    },
    */


    paths: {
        "jquery": "Vendors/jquery",
        "underscore": "Vendors/underscore",
        "backbone": "Vendors/backbone",

        "Distribution": "Distribution/Distribution",
        "Distribution.Router": "Distribution/Plugins/Router"
    }

});

I now can use my full library with:

require(['Distribution.Router'], function(Distribution) {});

when I uncomment the map configuration so I can use the full loaded module with router extension this way:

require(['Distribution'], function(Distribution) {});

than I am getting a module timeout.

What am I doing wrong?

Was it helpful?

Solution

When you map Distribution to Distribution.Router, you're creating a circular dependency because Distribution.Router also depends on Distribution.

To fix this just add another line overriding the map for Distribution in Distribution.Router only:

map: {
    "*": {
        "Distribution": "Distribution.Router"
    },
    "Distribution.Router": {
        "Distribution": "Distribution"
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top