Define `onClassName` once and use it twice
This commit is contained in:
parent
20e42ab8b0
commit
db9f5480c7
|
@ -63,48 +63,13 @@
|
|||
var remainingPath = path.slice(1);
|
||||
|
||||
if(remainingPath.length === 0) {
|
||||
return {field: (typeof json[first] !== undefined ? first : undefined), value: json[first]};
|
||||
return {field: (typeof json[first] !== 'undefined' ? first : undefined), value: json[first]};
|
||||
} else {
|
||||
return findNodeInJson(json[first], remainingPath)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
var optionsLeft = {
|
||||
mode: 'tree',
|
||||
onError: function (err) {
|
||||
alert(err.toString());
|
||||
},
|
||||
onClassName: function({ path, field, value }) {
|
||||
var thisNode = findNodeInJson(jsonLeft, path);
|
||||
var oppositeNode = findNodeInJson(jsonRight, path);
|
||||
var isValueEqual = JSON.stringify(thisNode.value) === JSON.stringify(oppositeNode.value);
|
||||
|
||||
if(Array.isArray(thisNode.value) && Array.isArray(oppositeNode.value)) {
|
||||
isValueEqual = thisNode.value.every(function (e) {
|
||||
return oppositeNode.value.includes(e);
|
||||
})
|
||||
}
|
||||
|
||||
if (thisNode.field === oppositeNode.field && isValueEqual) {
|
||||
return 'the_same_element';
|
||||
} else {
|
||||
return 'different_element'
|
||||
}
|
||||
},
|
||||
onChangeJSON: function (j) {
|
||||
jsonLeft = j;
|
||||
window.editorRight.refresh()
|
||||
}
|
||||
};
|
||||
|
||||
var optionsRight = {
|
||||
mode: 'tree',
|
||||
onError: function (err) {
|
||||
alert(err.toString());
|
||||
},
|
||||
onClassName: function({ path, field, value }) {
|
||||
|
||||
function onClassName({ path, field, value }) {
|
||||
var thisNode = findNodeInJson(jsonRight, path);
|
||||
var oppositeNode = findNodeInJson(jsonLeft, path);
|
||||
var isValueEqual = JSON.stringify(thisNode.value) === JSON.stringify(oppositeNode.value);
|
||||
|
@ -120,7 +85,26 @@
|
|||
} else {
|
||||
return 'different_element'
|
||||
}
|
||||
}
|
||||
|
||||
var optionsLeft = {
|
||||
mode: 'tree',
|
||||
onError: function (err) {
|
||||
alert(err.toString());
|
||||
},
|
||||
onClassName: onClassName,
|
||||
onChangeJSON: function (j) {
|
||||
jsonLeft = j;
|
||||
window.editorRight.refresh()
|
||||
}
|
||||
};
|
||||
|
||||
var optionsRight = {
|
||||
mode: 'tree',
|
||||
onError: function (err) {
|
||||
alert(err.toString());
|
||||
},
|
||||
onClassName: onClassName,
|
||||
onChangeJSON: function (j) {
|
||||
jsonRight = j;
|
||||
window.editorLeft.refresh();
|
||||
|
|
Loading…
Reference in New Issue