Skip to content

Commit 85ceae2

Browse files
committed
"dump" array keys and object property names
1 parent 566d667 commit 85ceae2

4 files changed

Lines changed: 74 additions & 38 deletions

File tree

src/js/main.js

Lines changed: 46 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2821,41 +2821,41 @@
28212821
var _createAssigner = createAssigner;
28222822

28232823
/**
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).
28312829
*
28322830
* **Note:** This method mutates `object`.
28332831
*
28342832
* @static
28352833
* @memberOf _
2836-
* @since 0.5.0
2834+
* @since 4.0.0
28372835
* @category Object
28382836
* @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.
28402839
* @returns {Object} Returns `object`.
28412840
* @example
28422841
*
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+
* }
28462847
*
2847-
* var other = {
2848-
* 'a': [{ 'c': 3 }, { 'e': 5 }]
2849-
* };
2848+
* var object = { 'a': [1], 'b': [2] };
2849+
* var other = { 'a': [3], 'b': [4] };
28502850
*
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] }
28532853
*/
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);
28562856
});
28572857

2858-
var merge_1 = merge;
2858+
var mergeWith_1 = mergeWith;
28592859

28602860
function DumpObject (dump) {
28612861
this.dumper = dump;
@@ -2941,7 +2941,14 @@
29412941
classDefinition[noInherit[i]] = {};
29422942
}
29432943
}
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+
})));
29452952
for (i = 0, count = noInherit.length; i < count; i++) {
29462953
if (Object.keys(abs[noInherit[i]]).length < 2) {
29472954
continue
@@ -3305,12 +3312,15 @@
33053312
? ' <span class="t_type">' + info.type + '</span>'
33063313
: ''
33073314
) +
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+
}) +
33143324
(info.value !== self.dumper.UNDEFINED
33153325
? ' <span class="t_operator">=</span> ' +
33163326
self.dumper.dump(info.value)
@@ -4610,9 +4620,17 @@
46104620
};
46114621

46124622
Dump.prototype.dumpArrayValue = function (key, val, withKey) {
4623+
var classes = ['t_key'];
4624+
if (/^\d+$/.test(key)) {
4625+
classes.push('t_int');
4626+
}
46134627
return withKey
46144628
? '\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+
}) +
46164634
'<span class="t_operator">=&gt;</span>' +
46174635
this.dump(val) +
46184636
'</li>\n'

src/js/main.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/js_src/Logger/Dump.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,17 @@ Dump.prototype.dumpArray = function (array) {
210210
}
211211

212212
Dump.prototype.dumpArrayValue = function (key, val, withKey) {
213+
var classes = ['t_key']
214+
if (/^\d+$/.test(key)) {
215+
classes.push('t_int');
216+
}
213217
return withKey
214218
? '\t<li>' +
215-
'<span class="t_key' + (/^\d+$/.test(key) ? ' t_int' : '') + '">' + key + '</span>' +
219+
this.dump(key, {
220+
attribs : {
221+
class: classes
222+
}
223+
}) +
216224
'<span class="t_operator">=&gt;</span>' +
217225
this.dump(val) +
218226
'</li>\n'

src/js_src/Logger/DumpObject.js

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import $ from 'jquery' // external global
2-
import merge from 'lodash/merge'
2+
import mergeWith from 'lodash/mergeWith'
33

44
export function DumpObject (dump) {
55
this.dumper = dump
@@ -85,7 +85,14 @@ DumpObject.prototype.dump = function (abs) {
8585
classDefinition[noInherit[i]] = {}
8686
}
8787
}
88-
abs = JSON.parse(JSON.stringify(merge({}, classDefinition, abs)))
88+
abs = JSON.parse(JSON.stringify(mergeWith({}, classDefinition, abs, function (objValue, srcValue) {
89+
if (objValue === null || srcValue === null) {
90+
return
91+
}
92+
if (typeof objValue === 'object' && Object.keys(objValue).length === 0 && typeof srcValue === 'object') {
93+
return srcValue
94+
}
95+
})))
8996
for (i = 0, count = noInherit.length; i < count; i++) {
9097
if (Object.keys(abs[noInherit[i]]).length < 2) {
9198
continue
@@ -449,12 +456,15 @@ DumpObject.prototype.dumpProperties = function (abs, meta) {
449456
? ' <span class="t_type">' + info.type + '</span>'
450457
: ''
451458
) +
452-
' <span class="t_identifier"' +
453-
(phpDocOut && info.desc
454-
? ' title="' + info.desc.escapeHtml() + '"'
455-
: ''
456-
) +
457-
'>' + name + '</span>' +
459+
' ' + self.dumper.dump(name, {
460+
addQuotes: /[\s\r\n]/.test(name) || name === '',
461+
attribs: {
462+
class: ['t_identifier'],
463+
title: phpDocOut && info.desc
464+
? info.desc
465+
: null
466+
}
467+
}) +
458468
(info.value !== self.dumper.UNDEFINED
459469
? ' <span class="t_operator">=</span> ' +
460470
self.dumper.dump(info.value)

0 commit comments

Comments
 (0)