UNPKG

2.17 kBJavaScriptView Raw
1"use strict";
2/**
3 * @license
4 * Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
5 * This code may only be used under the BSD style license found at
6 * http://polymer.github.io/LICENSE.txt
7 * The complete set of authors may be found at
8 * http://polymer.github.io/AUTHORS.txt
9 * The complete set of contributors may be found at
10 * http://polymer.github.io/CONTRIBUTORS.txt
11 * Code distributed by Google as part of the polymer project is also
12 * subject to an additional IP rights grant found at
13 * http://polymer.github.io/PATENTS.txt
14 */
15var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
16 return new (P || (P = Promise))(function (resolve, reject) {
17 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
18 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
19 function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
20 step((generator = generator.apply(thisArg, _arguments || [])).next());
21 });
22};
23Object.defineProperty(exports, "__esModule", { value: true });
24/**
25 * Resolves requests via one of a sequence of loaders.
26 */
27class MultiUrlLoader {
28 constructor(_loaders) {
29 this._loaders = _loaders;
30 for (const loader of _loaders) {
31 if (loader.readDirectory !== undefined) {
32 this.readDirectory = (path, deep) => {
33 return loader.readDirectory(path, deep);
34 };
35 break;
36 }
37 }
38 }
39 canLoad(url) {
40 return this._loaders.some((loader) => loader.canLoad(url));
41 }
42 load(url) {
43 return __awaiter(this, void 0, void 0, function* () {
44 for (const loader of this._loaders) {
45 if (loader.canLoad(url)) {
46 return loader.load(url);
47 }
48 }
49 return Promise.reject(new Error(`Unable to load ${url}`));
50 });
51 }
52}
53exports.MultiUrlLoader = MultiUrlLoader;
54//# sourceMappingURL=multi-url-loader.js.map
\No newline at end of file