@loaders.gl/core
Version:
Framework-independent loaders for 3D graphics formats
102 lines (86 loc) • 3.1 kB
JavaScript
import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
import { isFileReadable } from '../javascript-utils/is-type';
import { fetchFile } from './fetch/fetch-file';
import { isLoaderObject } from './loader-utils/normalize-loader';
import { mergeLoaderAndUserOptions } from './loader-utils/normalize-options';
import { selectLoader } from './select-loader';
import { parse } from './parse';
import { parseInBatches } from './parse-in-batches';
export function loadInBatches(_x, _x2, _x3) {
return _loadInBatches.apply(this, arguments);
}
function _loadInBatches() {
_loadInBatches = _asyncToGenerator(_regeneratorRuntime.mark(function _callee(url, loaders, options) {
var response;
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.next = 2;
return fetchFile(url, options);
case 2:
response = _context.sent;
return _context.abrupt("return", parseInBatches(response, loaders, options, url));
case 4:
case "end":
return _context.stop();
}
}
}, _callee);
}));
return _loadInBatches.apply(this, arguments);
}
export function load(_x4, _x5, _x6) {
return _load.apply(this, arguments);
}
function _load() {
_load = _asyncToGenerator(_regeneratorRuntime.mark(function _callee2(url, loaders, options) {
var autoUrl, loader, loaderOptions, data;
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
if (!Array.isArray(loaders) && !isLoaderObject(loaders)) {
options = loaders;
loaders = null;
}
autoUrl = isFileReadable(url) ? url.name : url;
loader = selectLoader(loaders, autoUrl, null, {
nothrow: true
});
if (!loader) {
_context2.next = 9;
break;
}
if (!loader.loadAndParse) {
_context2.next = 9;
break;
}
loaderOptions = mergeLoaderAndUserOptions(options, loader);
_context2.next = 8;
return loader.loadAndParse(url, loaderOptions);
case 8:
return _context2.abrupt("return", _context2.sent);
case 9:
data = url;
if (!(isFileReadable(data) || typeof data === 'string')) {
_context2.next = 14;
break;
}
_context2.next = 13;
return fetchFile(url, options);
case 13:
data = _context2.sent;
case 14:
return _context2.abrupt("return", parse(data, loaders, options, url));
case 15:
case "end":
return _context2.stop();
}
}
}, _callee2);
}));
return _load.apply(this, arguments);
}
//# sourceMappingURL=load.js.map