GateIn uses the AMD format to adapt to the web.
As a result, sometimes you can have to deal with included script that does not match with the
self-executing
function declaration format or the
requirejs
format expected by GateIn and is RequireJS integration. Custom code is
required for adapting the script to the expected format. To provide this bit of flexibility, it is possible to
declare an adapter that will wrap the adapted script.
The jQuery library is a good example on how a custom adapter is useful. Thanks to the adapter, you can reuse the jQuery without any change, ease the integration and maintain of this library in GateIn. jQuery uses the following constructor to define itself:
(function(window, undefined) { })(window);
The main issue with this constructor is that it will bind jQuery to the window but most importantly it will not return any value as expected by the dependency system. Thanks to the custom adapter, you can integrate it trivially:
<module>
<name>jquery</name>
<script>
<adapter>
(function() {
<include>/jquery.js</include>
return jQuery.noConflict(true);
})();
</adapter>
</script>
</module>
The
adapter
tag can contain mixed content and the
include
tag will perform a merge inclusion (as C language) of the original jQuery script in the resulting
module:
define("SHARED/jquery", [], function() { return (function() { (function(window, undefined) { })(window); return jQuery.noConflict(true); })(); });