3 'intern/dojo/node!babel-core',
4 'intern/dojo/node!react'
5 ], function (request
, babel
, react
) {
7 * React has AMD support so when require is present it will behave as a module
8 * The react example however expects a global React so we need to put it back
11 function globalizeReact() {
12 var global
= (function () {
15 global
.React
= global
.React
|| react
;
20 * A function that is called to load a resource.
22 * @param name The name of the resource to load.
23 * @param req A local "require" function to use to load other modules.
24 * @param onload A function to call with the value for name. This tells the loader that the plugin is done
25 * loading the resource. onload.error() can be called, passing an error object to it, if the plugin
26 * detects an error condition that means the resource will fail to load correctly.
28 load: function (name
, req
, onload
) {
31 request(req
.toUrl(name
)).then(function (sourceCode
) {
32 // Compile the JSX source into JavaScript code
33 var javascriptCode
= babel
.transform(sourceCode
,{presets
:['es2015', 'react']}).code
;
35 // Execute the compiled function. In this case the example code
36 // puts things into the global space so it needs to be run in a script tag.
37 var codeNode
= document
.createTextNode(javascriptCode
);
38 var node
= document
.createElement('script');
39 node
.type
= 'text/javascript';
40 node
.appendChild(codeNode
);
41 document
.head
.appendChild(node
);