MCPcopy Create free account
hub / github.com/reactjs/react-rails / loadScripts

Function loadScripts

lib/assets/javascripts/JSXTransformer.js:226–292  ·  view source on GitHub ↗

* Loop over provided script tags and get the content, via innerHTML if an * inline script, or by using XHR. Transforms are applied if needed. The scripts * are executed in the order they are found on the page. * * @param {array} scripts The elements to load and run. * @internal

(scripts)

Source from the content-addressed store, hash-verified

224 * @internal
225 */
226function loadScripts(scripts) {
227 var result = [];
228 var count = scripts.length;
229
230 function check() {
231 var script, i;
232
233 for (i = 0; i < count; i++) {
234 script = result[i];
235
236 if (script.loaded && !script.executed) {
237 script.executed = true;
238 run(script.content, script.url, script.options);
239 } else if (!script.loaded && !script.error && !script.async) {
240 break;
241 }
242 }
243 }
244
245 scripts.forEach(function(script, i) {
246 var options = {
247 sourceMap: true
248 };
249 if (/;harmony=true(;|$)/.test(script.type)) {
250 options.harmony = true;
251 }
252 if (/;stripTypes=true(;|$)/.test(script.type)) {
253 options.stripTypes = true;
254 }
255
256 // script.async is always true for non-javascript script tags
257 var async = script.hasAttribute('async');
258
259 if (script.src) {
260 result[i] = {
261 async: async,
262 error: false,
263 executed: false,
264 content: null,
265 loaded: false,
266 url: script.src,
267 options: options
268 };
269
270 load(script.src, function(content) {
271 result[i].loaded = true;
272 result[i].content = content;
273 check();
274 }, function() {
275 result[i].error = true;
276 check();
277 });
278 } else {
279 result[i] = {
280 async: async,
281 error: false,
282 executed: false,
283 content: script.innerHTML,

Callers 1

runScriptsFunction · 0.85

Calls 2

loadFunction · 0.85
checkFunction · 0.85

Tested by

no test coverage detected