MCPcopy
hub / github.com/scutan90/DeepLearning-500-questions / get

Function get

docsify.js:463–524  ·  view source on GitHub ↗

* Simple ajax get * @param {string} url * @param {boolean} [hasBar=false] has progress bar * @return { then(resolve, reject), abort }

(url, hasBar, headers)

Source from the content-addressed store, hash-verified

461 * @return { then(resolve, reject), abort }
462 */
463 function get(url, hasBar, headers) {
464 if ( hasBar === void 0 ) hasBar = false;
465 if ( headers === void 0 ) headers = {};
466
467 var xhr = new XMLHttpRequest();
468 var on = function () {
469 xhr.addEventListener.apply(xhr, arguments);
470 };
471 var cached$$1 = cache[url];
472
473 if (cached$$1) {
474 return {then: function (cb) { return cb(cached$$1.content, cached$$1.opt); }, abort: noop}
475 }
476
477 xhr.open('GET', url);
478 for (var i in headers) {
479 if (hasOwn.call(headers, i)) {
480 xhr.setRequestHeader(i, headers[i]);
481 }
482 }
483 xhr.send();
484
485 return {
486 then: function (success, error) {
487 if ( error === void 0 ) error = noop;
488
489 if (hasBar) {
490 var id = setInterval(
491 function (_) { return progressbar({
492 step: Math.floor(Math.random() * 5 + 1)
493 }); },
494 500
495 );
496
497 on('progress', progressbar);
498 on('loadend', function (evt) {
499 progressbar(evt);
500 clearInterval(id);
501 });
502 }
503
504 on('error', error);
505 on('load', function (ref) {
506 var target = ref.target;
507
508 if (target.status >= 400) {
509 error(target);
510 } else {
511 var result = (cache[url] = {
512 content: target.response,
513 opt: {
514 updatedAt: xhr.getResponseHeader('last-modified')
515 }
516 });
517
518 success(result.content, result.opt);
519 }
520 });

Callers 5

cssVarsFunction · 0.85
walkFetchEmbedFunction · 0.85
loadNestedFunction · 0.85
requestFunction · 0.85
fetchMixinFunction · 0.85

Calls 2

progressbarFunction · 0.85
onFunction · 0.85

Tested by

no test coverage detected