export function getStatefulPropsContext(reducers, { getState, setState }) { const boundReducers = bindReducersToState(reducers, { getState, setState }); const combineFunctionsCustomizer = (objValue, srcValue) => { if (_.isFunction(srcValue) && _.isFunction(objValue)) { return function (...args) { objValue(...args); return srcValue(...args); }; } return overwriteArrays(objValue, srcValue); }; const bindFunctionOverwritesCustomizer = (objValue, srcValue) => { if (_.isFunction(srcValue) && _.isFunction(objValue)) { return bindReducerToState(srcValue, { getState, setState }, objValue.path); } return overwriteArrays(objValue, srcValue); }; return { getPropReplaceReducers(props) { return _.mergeWith({}, boundReducers, getState(), props, bindFunctionOverwritesCustomizer); }, getProps(props) { return _.mergeWith({}, boundReducers, getState(), props, combineFunctionsCustomizer); } }; };
const applyDefaults = function(common, cfg) { const config = _.mergeWith({}, common, cfg, mergeFunction); // extend config const defaults = {}; return _.mergeWith( webpackDefaults(config), defaults, config, mergeFunction ); };
module.exports.mergeResults = function(resultSet) { var numSets = resultSet.length; var fixPercentage = ["Accuracy", "macroPrecision", "macroRecall", "macroF1", "microPrecision", "microRecall", "microF1", "HammingLoss", "HammingGain", "Recall", "Precision", "F1" ] var object = {}; var customizer = function(val1, val2) { if (_.isNumber(val1) && _.isNumber(val2)) { return val1 + val2; } if (lo.isPlainObject(val1) && lo.isPlainObject(val2)) { return lo.mergeWith(val1, val2, customizer); } } for (var i = 0; i < resultSet.length; i++) { object = lo.mergeWith(object, resultSet[i], customizer); } traverse(object).forEach(function (value) { if (fixPercentage.indexOf(this.key) !== -1) { this.update(+((value / numSets).toFixed(3))); } }); return object; }
applications.forEach(app => { result = _.mergeWith(result, app.config, (a, b) => { if (_.isArray(a)) { return _.uniq(a.concat(b || [])); } }); });
export function overrideConfigJSON( config: ?Object, interfaceConfig: ?Object, loggingConfig: ?Object, json: Object) { for (const configName of Object.keys(json)) { let configObj; if (configName === 'config') { configObj = config; } else if (configName === 'interfaceConfig') { configObj = interfaceConfig; } else if (configName === 'loggingConfig') { configObj = loggingConfig; } if (configObj) { const configJSON = _getWhitelistedJSON(configName, json[configName]); if (!_.isEmpty(configJSON)) { logger.info( `Extending ${configName} with: ${ JSON.stringify(configJSON)}`); // eslint-disable-next-line arrow-body-style _.mergeWith(configObj, configJSON, (oldValue, newValue) => { // XXX We don't want to merge the arrays, we want to // overwrite them. return Array.isArray(oldValue) ? newValue : undefined; }); } } } }
_readConfigFile(name: string) { let configPath = path.join(this.options.config, `${name}.yml`); let result; if (pathExists.sync(configPath)) { result = yaml.load(fs.readFileSync(configPath, ENCODING), {filename: configPath}); } else { configPath = path.join(this.options.config, `${name}.json`); if (pathExists.sync(configPath)) { result = JSON.parse(fs.readFileSync(configPath)); } else { result = {}; } } let filenames = glob.sync(`${name}-*.@(yml|json)`, { cwd: this.options.config }); if (filenames) { filenames = filenames.sort(); } for (let filename of filenames) { let filePath = path.join(this.options.config, filename); let obj; if (filename.match(/.*\.yml/)) { obj = yaml.load(fs.readFileSync(filePath, ENCODING), {filename: filePath}); } else if (filename.match(/.*\.json/)) { obj = JSON.parse(fs.readFileSync(filePath)); } _.mergeWith(result, obj, (objValue, srcValue) => { if (_.isArray(objValue)) { return objValue.concat(srcValue); } }); } return result; }
findOnePopulated: function(criteria, opts) { function customizer(objValue, srcValue) { if (_.isArray(objValue)) { return objValue.concat(srcValue); } } var options = _.mergeWith({ where: criteria, include: [ {model: Argument, as: 'arguments', attributes: ['name', 'description', 'topic_id'], separate:true }, {model: Section, as: 'sections', attributes: ['name', 'description', 'topic_id'], separate:true }, {model: Tag, as: 'keywords', attributes: ['name']}, {model: Alias, as: 'aliases', attributes: ['name', 'topic_id'], separate: true }, {model: Example, as: 'user_examples', include: [{model: User, as: 'user', attributes: ['username']}] }, { model: PackageVersion, as: 'package_version', attributes: ['package_name', 'version'] } ] }, opts, customizer); return Topic.findOne(options); },
function merge (destination, source) { return _.mergeWith(destination, source, (objValue, srcValue) => { if (_.isArray(objValue)) { return objValue.concat(srcValue) } }) }
Pipeline.prototype._mergePluginHookResultIntoContext = function(context,result) { return _.mergeWith(context, result, function(a, b) { if (_.isArray(a)) { return a.concat(b); } }); };
test('Configuring package.json with angular2/webpack/less', t => { const expected = _.mergeWith({}, pkg, { devDependencies: {'gulp-less': '^3.0.5'} }); TestUtils.call(context, 'configuring.pkg', {framework: 'angular2', modules: 'webpack', css: 'less'}); t.deepEqual(context.mergeJson['package.json'], expected); });
const mergeConfig = (source, ...destinations) => { return mergeWith({}, source, ...destinations, (srcVal, destVal) => { if (isArray(srcVal) && isArray(destVal)) { return srcVal.concat(destVal); } }); };
module.exports = async ({preset, config, parserOpts, writerOpts}) => { let loadedConfig = {}; if (preset) { const presetPackage = `conventional-changelog-${preset.toLowerCase()}`; try { loadedConfig = importFrom.silent(__dirname, presetPackage) || importFrom(process.cwd(), presetPackage); } catch (err) { throw new SemanticReleaseError(`Preset: "${preset}" does not exist: ${err.message}`, err.code); } } else if (config) { try { loadedConfig = importFrom.silent(__dirname, config) || importFrom(process.cwd(), config); } catch (err) { throw new SemanticReleaseError(`Config: "${config}" does not exist: ${err.message}`, err.code); } } else if (!parserOpts || !writerOpts) { loadedConfig = conventionalChangelogAngular; } if (typeof loadedConfig === 'function') { loadedConfig = await pify(loadedConfig)(); } else { loadedConfig = await loadedConfig; } return mergeWith( {}, !preset && !config && parserOpts ? {parserOpts} : {parserOpts: loadedConfig.parserOpts}, {parserOpts}, !preset && !config && writerOpts ? {writerOpts} : {writerOpts: loadedConfig.writerOpts}, {writerOpts}, (value, source) => (Array.isArray(value) ? source : undefined) ); };
Model.findById(req.params.id, function (err, model) { /*for (var p in req.body) { if (req.body[p] == 'null') model[p] = null; else model[p] = req.body[p]; }*/ _.mergeWith(model, req.body, (objValue, srcValue) => { if (_.isArray(objValue)) { return srcValue; } }); model.save(function (err, data) { if (err) res.status(500).send(err); else { Model.findById(data.id, function (err, m) { if (err) res.status(500).send(err); else { res.status(201).send(m); } }); } }); });
var customizer = function(val1, val2) { if (_.isNumber(val1) && _.isNumber(val2)) { return val1 + val2; } if (lo.isPlainObject(val1) && lo.isPlainObject(val2)) { return lo.mergeWith(val1, val2, customizer); } }
toChangeInState: (expectedChanges) => { const expected = _.mergeWith(originalState, expectedChanges, toChangeInStateCustomizer); expect(newState).toEqual(expected); // expect(mutated).toEqual(false); if (mutated) { throw new Error('state mutated after running reducer'); } }
var unindexed = this.collapsePaths(this.state.unindexed, function(u1, u2) { _.mergeWith(u1, u2, function(p1, p2) { return { times: p1.times + p2.times, query: p1.query, }; }); });
this.set = function (newConfig) { _.mergeWith(config, newConfig, function (obj, src) { // Overwrite arrays to keep consistent with #283 if (_.isArray(src)) { return src } }) }
// Same concept as _.merge, but don't overwrite properties that have already been assigned function mergeDefaults(a, b) { return _.mergeWith(a, b, objectValue => { // If it's an object, let _ handle it this time, we will be called again for each property if (!_.isPlainObject(objectValue) && objectValue !== undefined) { return objectValue; } }); }
export function mergeDaysHashes (oldDaysHash, newDaysHash) { oldDaysHash = {...oldDaysHash}; const mergedDaysHash = _.mergeWith(oldDaysHash, newDaysHash, (oldDayItems, newDayItems) => { if (oldDayItems == null) oldDayItems = []; return mergeItems(oldDayItems, newDayItems); }); return mergedDaysHash; }
.forEach(part => { config_interim = _.mergeWith( {}, config_interim, part(config_interim), (objValue, srcValue) => _.isArray(objValue) ? objValue.concat(srcValue) : undefined, ); });
function deepMerge(object, source) { return _.mergeWith(object, source, function(objValue, srcValue) { if (_.isObject(objValue) && srcValue) { return deepMerge(objValue, srcValue); } return objValue; }); }
Item.prototype.set = function(params) { this.attrs = _.mergeWith({}, this.attrs, params, function(o, n) { if(_.isArray(n)) { return n; } }); return this; };
module.exports = (function(isProduction){ var mergeMethod = function(objValue, srcValue){ if (_.isArray(objValue)) { return objValue.concat(srcValue); } }; return _.mergeWith(GENERIC_PARAMS, isProduction ? DIST_PARAMS : DEV_PARAMS, mergeMethod); })(isProd);
module.exports = function(webpack, options, externalConfig) { var config = generate(webpack, options); var finalExternalConfig = typeof externalConfig == 'function' ? externalConfig({ }) : externalConfig; _.mergeWith(config, finalExternalConfig, customizer); return config; }
function customizer(objValue, srcValue) { if (_.isArray(objValue)) { return objValue.concat(srcValue); } if (_.isPlainObject(objValue)) { return _.mergeWith({}, objValue, srcValue, (a, b) => _.compact(_.flatten([a, b]))); } return undefined; }
constructor( oOptions ){ // Calling super constructor super(); // Extending oOptions = _.extend({ sID: 'EndpointGeneric', sHeader: null, sEncoding: null, iMaxRepeat: -1, // Number of times to repeat //iMaxTps //Telgrams per seconds aDatagrams: null, bIsAncilla: false, module: null, oLogger: null }, oOptions ); // Merging oOptions = _.mergeWith({ aOfferedEvents: [ 'error', 'data', 'datagram' ] }, oOptions, function( objValue, srcValue ){ if (_.isArray(objValue)) { return objValue.concat(srcValue); } } ); oOptions.sHeader = ( oOptions.sHeader ? oOptions.sHeader + ' ': '' ) + '[ Endpoint: "' + oOptions.sID + '" ]'; this.__oOptions = oOptions; // Init logger and extends loggind methods on this class let oLogOptions = { sID: 'Endpoint-' + this.__oOptions.sID, sHeader: this.__oOptions.sHeader, }; let _oLogger = ( oOptions.oLogger ? oOptions.oLogger : require( './Logger.singleton' ) ); _oLogger.extend( oLogOptions.sID, this, oLogOptions ); this.__oEndpoint = null; this.__oPromiseReady = null; // Init Datagrams rules this.__initDatagrams(); // Handling configured datagrams if present let _Endpoint = this; this.on( 'data', function( oBuffer ){ if( _Endpoint.__bUseDatagrams() ){ _Endpoint.__checkValidDatagram( oBuffer ) .then( function( oDatagram ){ // Handling specific events onReceive if needed return oDatagram.onReceive( oBuffer ) .then(function(){ _Endpoint.emit( 'datagram', oDatagram, oBuffer, oDatagram.parse( oBuffer ) ); }) ; }) .catch( function( oError ){ _Endpoint.warn( 'Error "%s": Unable to decode a datagram from buffer: "%s"', oError, oBuffer.toString( _Endpoint.__oOptions.sEncoding ) ); // TODO: handle catch situation when the current oBuffer is not a valid datagram ( the current oBuffer should be added to previous oBuffer and checked again to find an acceptable datagram or trashed away ) }) ; } }); }
const applyDefaults = function(common, cfg) { const config = _.mergeWith({}, common, cfg, mergeFunction); // extend config const defaults = { devtool: 'cheap-module-eval-source-map', html: { template: path.join(__dirname, 'assets', 'component.html.ejs'), chunksSortMode: 'id', }, }; return _.mergeWith( webpackDefaults(config), defaults, config, mergeFunction ); };
export function mergeDaysHashes (oldDaysHash, newDaysHash) { oldDaysHash = {...oldDaysHash}; const mergedDaysHash = _.mergeWith(oldDaysHash, newDaysHash, (oldDayItems, newDayItems) => { if (oldDayItems == null) oldDayItems = []; // this is only called when necessary to merge new items into old items. // that way we avoid sorting items that have already been sorted. return mergeItems(oldDayItems, newDayItems); }); return mergedDaysHash; }
files.forEach(function(file) { var configFilePath = path.join(configDir, file + '.yml'); var envConfig = yaml.safeLoad(fs.readFileSync(configFilePath, 'utf8')); config = _.mergeWith(config, envConfig, function(baseValue, envValue) { if (_.isArray(baseValue) && _.isArray(envValue)) { return envValue; } }); });
const deepMerge = (lhs, rhs) => { if (lhs === undefined || lhs === null) { return rhs } else if (Array.isArray(lhs)) { return lhs.concat(rhs) } else if (typeof lhs === 'object') { return _.mergeWith(lhs, rhs, deepMerge) } else { return rhs } }