GateIn will translate into an AMD module:
define("SHARED/foo", ["SHARED/jquery"], function(jQuery) { return (function($) { // Do something with jQuery })(jQuery); });
Logical identifiers are translated into AMD identifiers.
The
foo
module is translated into the
SHARED/foo
AMD module identifier, the
SHARED
prefix is added by GateIn for scoping the name. There are other existing scopes, such as
PORTLET
and
PORTAL
.
The dependency on the
jquery
module is translated into a ["SHARED/jquery"]
AMD module dependency.
The module function is wrapped twice:
At first, it is wrapped by the GateIn module wrapper that delegates to the module function which aims to provide a lazy evaluation of the module self-executing function.
Then, it is wrapped by the
define
AMD function that takes care of loading the module properly.
The self-executing function module arguments must match the module dependencies expressed in the XML declaration.
The
jquery
dependency is aliased to the
jQuery
name thanks to the XML
as
tag. As a result, the GateIn function wrapper parameter is named
jQuery
.
The argument of the module self-executing function is named
jQuery
to match the declared alias.
The parameter of the module self-executing function is named
$
and thus redefines the
jquery
dependency to
$
locally.
At runtime, the following happens:
The define
function is invoked and declares the dependency.
When the dependency is resolved (for example, the jquery module is loaded and available).
The module wrapper is invoked with the
jQuery
argument containing the
jquery
dependency.
The module wrapper evaluates the self-executing function that resolves the
jQuery
argument to the
jquery
dependency.
The self-executing function is invoked and the
jquery
dependency is available under the $
name.