Load a chaplin module synchronously

82 views Asked by At

I'm trying to just load the event_broker module in the chaplinjs .
I am able to to do by doing something like

require(["underscore", "chaplin"], function(_, chaplin) 
{
var eventBroker = _({}).extend(chaplin.EventBroker);
});

But, this is not good enough in my case. I need to be able to load the event_broker module synchronously. I know that is what require designed to do. Is there a way to do that?

1

There are 1 answers

0
Louis On

I know that is what require designed to do.

No, that's not what RequireJS is designed to do. (Did you forget to put "not" in there?) RequireJS is designed to load modules asynchronously.

I would normally suggest loading Chaplin through a script element because that would be synchronous but, after looking at the code of Chaplin, I see that it fails with throw new Error('Chaplin requires Common.js or AMD modules'); if it does not detect a CommonJS or AMD environment.

Almond can be used to load bundles of AMD modules synchronously so this may be an option for you.