Modified mergeArrays function to accept arrays of different length.
Modified mergeArrays function to accept arrays of different length and merge the content of arrays.
This commit is contained in:
parent
058e0e2f56
commit
6b4fdb8fff
|
@ -2,7 +2,7 @@ var fs = require('fs');
|
|||
var path = require('path');
|
||||
var debug = require('debug')('loopback:boot:config-loader');
|
||||
var assert = require('assert');
|
||||
|
||||
var _=require('lodash');
|
||||
var ConfigLoader = exports;
|
||||
|
||||
/**
|
||||
|
@ -276,8 +276,7 @@ function mergeSingleItemOrProperty(target, config, key, fullKey) {
|
|||
|
||||
function mergeArrays(target, config, keyPrefix) {
|
||||
if (target.length !== config.length) {
|
||||
return 'Cannot merge array values of different length' +
|
||||
' for the option `' + keyPrefix + '`.';
|
||||
return mergeArraysDiffLength(target, config);
|
||||
}
|
||||
|
||||
// Use for(;;) to iterate over undefined items, for(in) would skip them.
|
||||
|
@ -290,6 +289,12 @@ function mergeArrays(target, config, keyPrefix) {
|
|||
return null; // no error
|
||||
}
|
||||
|
||||
function mergeArraysDiffLength(target, config) {
|
||||
var newTarget = _.cloneDeep(target, true);
|
||||
Array.prototype.splice.apply(target, [0, target.length].concat(_.union(newTarget, config)));
|
||||
}
|
||||
|
||||
|
||||
function hasCompatibleType(origValue, newValue) {
|
||||
if (origValue === null || origValue === undefined)
|
||||
return true;
|
||||
|
|
Loading…
Reference in New Issue