Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default function fetchAllData(components, getState, dispatch, location, params) {
const fetchers = components
.filter((component) => !!component) // Weed out 'undefined' routes
.filter((component) => component.fetchData) // only look at ones with a static fetchData()
.map((component) => component.fetchData) // pull out fetch data methods
.map(fetchData => {
return fetchData(getState, dispatch, location, params)
}) // call fetch data methods and return promises
return Promise.all(fetchers)
}
function findAllConfigs(options) {
var possibleFiles = possibleConfigs(options);
return Promise.all(possibleFiles.map(fsHelpers.exists)).then(function(exists) {
var realFiles = possibleFiles.filter(function(file, idx) {
return exists[idx];
});
return Promise.all(realFiles.map(function(file) {
var parsedConfig;
try {
parsedConfig = require(file);
parsedConfig.__source = file;
return Promise.resolve(parsedConfig);
} catch (err) {
return fsHelpers.read(file).then(function(content) {
parsedConfig = nodeEval('(' + content + ')');
var defaultLevels = levelList.filter(function(level) {
return levelsMap[level].default;
});
var levelByCwd = levelList.filter(function(level) {
return cwd.indexOf(level) === 0;
}).sort().reverse()[0];
levels = levelByCwd || (defaultLevels.length ? defaultLevels : cwd);
}
Array.isArray(entities) || (entities = [entities]);
Array.isArray(levels) || (levels = [levels]);
return Promise.all(entities.map(function(input) {
var isFileGlob = typeof input === 'string';
return Promise.all((isFileGlob ? braceExpansion(input) : [input]).map(function(filepathOrInput) {
var currentLevels = levels;
if (typeof filepathOrInput === 'string') {
var currentLevel = path.dirname(filepathOrInput);
currentLevel !== '.' && (currentLevels = [currentLevel]);
}
return Promise.all(currentLevels.map(function(relLevel) {
var rootDir = config.rootSync() || cwd,
level = path.resolve(rootDir, relLevel);
return config.level(level).then(function(levelOptions) {
levelOptions || (levelOptions = {});
return pify(fs.readdir, Promise)(pth).then(function (files) {
return Promise.all(files.map(function (file) {
return pify(rimraf, Promise)(path.join(pth, file));
}));
});
}));
.then((displays) => {
const snapsP = displays
.map(({ id }) => snapshot({ screen: id }))
Promise.all(snapsP)
.then(resolve)
.catch(reject)
})
.catch(reject)
return Promise.all(possibleFiles.map(fsHelpers.exists)).then(function(exists) {
var realFiles = possibleFiles.filter(function(file, idx) {
return exists[idx];
});
return Promise.all(realFiles.map(function(file) {
var parsedConfig;
try {
parsedConfig = require(file);
parsedConfig.__source = file;
return Promise.resolve(parsedConfig);
} catch (err) {
return fsHelpers.read(file).then(function(content) {
parsedConfig = nodeEval('(' + content + ')');
parsedConfig.__source = file;
return parsedConfig;
});
}
}));
function loadFonts (fonts) {
if (document.fonts && document.fonts.load) {
return Promise.all(fonts.map(function (font) {
return document.fonts.load(font)
}))
} else {
return new Promise(function (resolve) {
setTimeout(resolve, 500)
})
}
}
return this.get().then(function(config) {
var projectLevels = config.levels || [],
libNames = config.libs ? Object.keys(config.libs) : [],
commonOpts = Object.keys(config)
.filter(key => !specialKeys.has(key))
.reduce((acc, key) => {
acc[key] = config[key];
return acc;
}, {});
return Promise.all(libNames.map(function(libName) {
return _this.library(libName).then(function(bemLibConf) {
return bemLibConf.get().then(function(libConfig) {
return libConfig.levels;
});
});
})).then(function(libLevels) {
var allLevels = [].concat.apply([], libLevels.filter(Boolean)).concat(projectLevels);
return allLevels.reduce((res, lvl) => {
res[lvl.path] = merge({}, commonOpts, res[lvl.path] || {}, lvl);
return res;
}, {});
});
});
};