Define `onClassName` once and use it twice
This commit is contained in:
parent
20e42ab8b0
commit
db9f5480c7
|
@ -63,11 +63,28 @@
|
||||||
var remainingPath = path.slice(1);
|
var remainingPath = path.slice(1);
|
||||||
|
|
||||||
if(remainingPath.length === 0) {
|
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 {
|
} else {
|
||||||
return findNodeInJson(json[first], remainingPath)
|
return findNodeInJson(json[first], remainingPath)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
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'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var optionsLeft = {
|
var optionsLeft = {
|
||||||
|
@ -75,23 +92,7 @@
|
||||||
onError: function (err) {
|
onError: function (err) {
|
||||||
alert(err.toString());
|
alert(err.toString());
|
||||||
},
|
},
|
||||||
onClassName: function({ path, field, value }) {
|
onClassName: onClassName,
|
||||||
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) {
|
onChangeJSON: function (j) {
|
||||||
jsonLeft = j;
|
jsonLeft = j;
|
||||||
window.editorRight.refresh()
|
window.editorRight.refresh()
|
||||||
|
@ -103,24 +104,7 @@
|
||||||
onError: function (err) {
|
onError: function (err) {
|
||||||
alert(err.toString());
|
alert(err.toString());
|
||||||
},
|
},
|
||||||
onClassName: function({ path, field, value }) {
|
onClassName: onClassName,
|
||||||
|
|
||||||
var thisNode = findNodeInJson(jsonRight, path);
|
|
||||||
var oppositeNode = findNodeInJson(jsonLeft, 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) {
|
onChangeJSON: function (j) {
|
||||||
jsonRight = j;
|
jsonRight = j;
|
||||||
window.editorLeft.refresh();
|
window.editorLeft.refresh();
|
||||||
|
|
Loading…
Reference in New Issue