0
votes

I have a custom widget located in foo/bar.js declared like this:

define([
  ...
], function(
  ...
) {
  return {
    ...
  }
);

I am trying to use it inside other widget like this:

require([
  "foo/bar"
  ...
], function(bar, ..
..

But it would not get loaded. Does anyone have any suggestions?

When I type foo/bar in the console, it returns empty object Object {}. All worked fine when I was using old format and dojo.provide(). But once it was dropped the wiget became unvisible.

Important: the problem only occurs when I am trying to use Google-hosted Dojo:

<!--
<script src="{{ STATIC_URL }}js/dojo/dojo.js" type="text/javascript"></script>
!-->
<script src="//ajax.googleapis.com/ajax/libs/dojo/1.8.6/dojo/dojo.js"></script>

I have to use Google-hosted Dojo for debugging purpose, since STATIC_URL one takes 30-40 seconds to load (because it is uncompiled).

1

1 Answers

1
votes

First read this on the load of AMD modules used by dojo now: http://requirejs.org/docs/whyamd.html#definition

the way AMD works is that it will return the required module as a function parameter. You can use that module inside the function of your require call.

Let's say you have defined your foo/bar module. you can use it in the require like that:

require(["foo/bar"], function (anyVarName) {  // <- anyVarName will be your foo/bar return value
  console.dir(anyVarName);
}

anyVarName will only exist inside the function. Your code using it should be inside it.

you can require multiple modules and they will be passed as parameter in the same order as you require them

require(["foo/bar1","foo/bar2","foo/bar3"], function (bar1, bar2, bar3) {});

is that better ?