|
2821 | 2821 | var _createAssigner = createAssigner; |
2822 | 2822 |
|
2823 | 2823 | /** |
2824 | | - * This method is like `_.assign` except that it recursively merges own and |
2825 | | - * inherited enumerable string keyed properties of source objects into the |
2826 | | - * destination object. Source properties that resolve to `undefined` are |
2827 | | - * skipped if a destination value exists. Array and plain object properties |
2828 | | - * are merged recursively. Other objects and value types are overridden by |
2829 | | - * assignment. Source objects are applied from left to right. Subsequent |
2830 | | - * sources overwrite property assignments of previous sources. |
| 2824 | + * This method is like `_.merge` except that it accepts `customizer` which |
| 2825 | + * is invoked to produce the merged values of the destination and source |
| 2826 | + * properties. If `customizer` returns `undefined`, merging is handled by the |
| 2827 | + * method instead. The `customizer` is invoked with six arguments: |
| 2828 | + * (objValue, srcValue, key, object, source, stack). |
2831 | 2829 | * |
2832 | 2830 | * **Note:** This method mutates `object`. |
2833 | 2831 | * |
2834 | 2832 | * @static |
2835 | 2833 | * @memberOf _ |
2836 | | - * @since 0.5.0 |
| 2834 | + * @since 4.0.0 |
2837 | 2835 | * @category Object |
2838 | 2836 | * @param {Object} object The destination object. |
2839 | | - * @param {...Object} [sources] The source objects. |
| 2837 | + * @param {...Object} sources The source objects. |
| 2838 | + * @param {Function} customizer The function to customize assigned values. |
2840 | 2839 | * @returns {Object} Returns `object`. |
2841 | 2840 | * @example |
2842 | 2841 | * |
2843 | | - * var object = { |
2844 | | - * 'a': [{ 'b': 2 }, { 'd': 4 }] |
2845 | | - * }; |
| 2842 | + * function customizer(objValue, srcValue) { |
| 2843 | + * if (_.isArray(objValue)) { |
| 2844 | + * return objValue.concat(srcValue); |
| 2845 | + * } |
| 2846 | + * } |
2846 | 2847 | * |
2847 | | - * var other = { |
2848 | | - * 'a': [{ 'c': 3 }, { 'e': 5 }] |
2849 | | - * }; |
| 2848 | + * var object = { 'a': [1], 'b': [2] }; |
| 2849 | + * var other = { 'a': [3], 'b': [4] }; |
2850 | 2850 | * |
2851 | | - * _.merge(object, other); |
2852 | | - * // => { 'a': [{ 'b': 2, 'c': 3 }, { 'd': 4, 'e': 5 }] } |
| 2851 | + * _.mergeWith(object, other, customizer); |
| 2852 | + * // => { 'a': [1, 3], 'b': [2, 4] } |
2853 | 2853 | */ |
2854 | | - var merge = _createAssigner(function(object, source, srcIndex) { |
2855 | | - _baseMerge(object, source, srcIndex); |
| 2854 | + var mergeWith = _createAssigner(function(object, source, srcIndex, customizer) { |
| 2855 | + _baseMerge(object, source, srcIndex, customizer); |
2856 | 2856 | }); |
2857 | 2857 |
|
2858 | | - var merge_1 = merge; |
| 2858 | + var mergeWith_1 = mergeWith; |
2859 | 2859 |
|
2860 | 2860 | function DumpObject (dump) { |
2861 | 2861 | this.dumper = dump; |
|
2941 | 2941 | classDefinition[noInherit[i]] = {}; |
2942 | 2942 | } |
2943 | 2943 | } |
2944 | | - abs = JSON.parse(JSON.stringify(merge_1({}, classDefinition, abs))); |
| 2944 | + abs = JSON.parse(JSON.stringify(mergeWith_1({}, classDefinition, abs, function (objValue, srcValue) { |
| 2945 | + if (objValue === null || srcValue === null) { |
| 2946 | + return |
| 2947 | + } |
| 2948 | + if (typeof objValue === 'object' && Object.keys(objValue).length === 0 && typeof srcValue === 'object') { |
| 2949 | + return srcValue |
| 2950 | + } |
| 2951 | + }))); |
2945 | 2952 | for (i = 0, count = noInherit.length; i < count; i++) { |
2946 | 2953 | if (Object.keys(abs[noInherit[i]]).length < 2) { |
2947 | 2954 | continue |
|
3305 | 3312 | ? ' <span class="t_type">' + info.type + '</span>' |
3306 | 3313 | : '' |
3307 | 3314 | ) + |
3308 | | - ' <span class="t_identifier"' + |
3309 | | - (phpDocOut && info.desc |
3310 | | - ? ' title="' + info.desc.escapeHtml() + '"' |
3311 | | - : '' |
3312 | | - ) + |
3313 | | - '>' + name + '</span>' + |
| 3315 | + ' ' + self.dumper.dump(name, { |
| 3316 | + addQuotes: /[\s\r\n]/.test(name) || name === '', |
| 3317 | + attribs: { |
| 3318 | + class: ['t_identifier'], |
| 3319 | + title: phpDocOut && info.desc |
| 3320 | + ? info.desc |
| 3321 | + : null |
| 3322 | + } |
| 3323 | + }) + |
3314 | 3324 | (info.value !== self.dumper.UNDEFINED |
3315 | 3325 | ? ' <span class="t_operator">=</span> ' + |
3316 | 3326 | self.dumper.dump(info.value) |
|
4610 | 4620 | }; |
4611 | 4621 |
|
4612 | 4622 | Dump.prototype.dumpArrayValue = function (key, val, withKey) { |
| 4623 | + var classes = ['t_key']; |
| 4624 | + if (/^\d+$/.test(key)) { |
| 4625 | + classes.push('t_int'); |
| 4626 | + } |
4613 | 4627 | return withKey |
4614 | 4628 | ? '\t<li>' + |
4615 | | - '<span class="t_key' + (/^\d+$/.test(key) ? ' t_int' : '') + '">' + key + '</span>' + |
| 4629 | + this.dump(key, { |
| 4630 | + attribs : { |
| 4631 | + class: classes |
| 4632 | + } |
| 4633 | + }) + |
4616 | 4634 | '<span class="t_operator">=></span>' + |
4617 | 4635 | this.dump(val) + |
4618 | 4636 | '</li>\n' |
|
0 commit comments