lore
Version:
Convention-driven framework for building React-Redux applications
31 lines (27 loc) • 1.11 kB
JavaScript
import _result from 'lodash/result';
import _merge from 'lodash/merge';
import _reduce from 'lodash/reduce';
function getDefaultConfig(hooks) {
return _reduce(hooks, function (result, value, key) {
return _merge(result, _result(value, 'defaults'));
}, {});
}
/**
* Generate the final config from the combination of the overrides passed
* into the app, the default config (calculated from the hooks), and the
* user config for the project (loaded and compiled inside this function).
* configOverride takes priority, then the user config, and finally any defaults
* specified the hooks.
*
* @param {Object} configOverride passed into lore.build(configOverride)
*
* @param {Object} hooks Set of hooks that should be loaded
*
* @returns {Object} A reducer function that invokes every reducer inside the
* passed object, and builds a state object with the same shape.
*/
export default function getConfig(configOverride, hooks, loader) {
var defaultConfig = getDefaultConfig(hooks);
var userConfig = loader.loadUserConfig();
return _merge({}, defaultConfig, userConfig, configOverride);
}