MCPcopy
hub / github.com/fontello/fontello / loadAssets

Function loadAssets

client/lib/loader/loader.js:187–269  ·  view source on GitHub ↗
(pkgNames, preload)

Source from the content-addressed store, hash-verified

185 // `preload` parameter is an optional array of URLs which are needed to load
186 // before the given package.
187 function loadAssets(pkgNames, preload) {
188 var resources = [];
189 var scheduled = {};
190 var loadQueue = [];
191
192 pkgNames = Array.isArray(pkgNames) ? pkgNames : [ pkgNames ];
193
194 if (!pkgNames.length) {
195 return Promise.resolve();
196 }
197
198 for (var i = 0; i < pkgNames.length; i++) {
199 if (!assets[pkgNames[i]]) {
200 return Promise.reject(new Error('Unknown package (' + pkgNames[i] + ')'));
201 }
202
203 loadQueue = loadQueue.concat(assets[pkgNames[i]].packagesQueue.slice(0).reverse());
204 }
205
206 loadQueue = uniq(loadQueue);
207
208 forEach(loadQueue, function (dependency) {
209 var alreadyLoaded, pkgDist = assets[dependency];
210
211 if (pkgDist.css.length) {
212 alreadyLoaded = reduce(pkgDist.css, function (acc, css) {
213 return acc || loaded[css] || scheduled[css];
214 }, false);
215
216 if (!alreadyLoaded) {
217 resources.unshift(pkgDist.css[0]);
218 scheduled[pkgDist.css[0]] = true;
219 }
220 }
221
222 if (pkgDist.js.length) {
223 alreadyLoaded = reduce(pkgDist.js, function (acc, js) {
224 return acc || loaded[js] || scheduled[js];
225 }, false);
226
227 if (!alreadyLoaded) {
228 resources.unshift(pkgDist.js[0]);
229 scheduled[pkgDist.js[0]] = true;
230 }
231 }
232 });
233
234 // Copy the preload array to allow pushing without side-effects.
235 if (preload) {
236 resources = preload.concat(resources);
237 }
238
239 if (!resources.length) return Promise.resolve();
240
241 var res_list = [];
242 forEach(resources, function (url) {
243 res_list.push({
244 url: url,

Callers 1

loader.jsFile · 0.85

Calls 3

uniqFunction · 0.85
forEachFunction · 0.85
reduceFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…