From 00e99a791a2458dcca84836792c6c39625e3589c Mon Sep 17 00:00:00 2001 From: James Garbutt <43081j@users.noreply.github.com> Date: Fri, 9 Feb 2018 14:57:51 +0000 Subject: [PATCH 1/3] cache parent errors --- src/js/treemode.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/js/treemode.js b/src/js/treemode.js index 78d28d4..b5ffa5c 100644 --- a/src/js/treemode.js +++ b/src/js/treemode.js @@ -435,6 +435,8 @@ treemode.validate = function () { } } + var parentErrors = []; + // display the error in the nodes with a problem this.errorNodes = duplicateErrors .concat(schemaErrors) @@ -443,7 +445,11 @@ treemode.validate = function () { // original entries last return entry.node .findParents() + .filter(function (parent) { + return parentErrors.indexOf(parent) === -1; + }) .map(function (parent) { + parentErrors.push(parent); return { node: parent, child: entry.node, From 106a75c46a12c01e568d05c7b268a8c5734e7eba Mon Sep 17 00:00:00 2001 From: 43081j <43081j@users.noreply.github.com> Date: Tue, 13 Feb 2018 19:38:26 +0000 Subject: [PATCH 2/3] refactor error node computation --- src/js/treemode.js | 50 +++++++++++++++++++++------------------------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/src/js/treemode.js b/src/js/treemode.js index b5ffa5c..dac4014 100644 --- a/src/js/treemode.js +++ b/src/js/treemode.js @@ -435,34 +435,30 @@ treemode.validate = function () { } } - var parentErrors = []; + var errorNodes = duplicateErrors.concat(schemaErrors); + var parents = errorNodes + .reduce(function (all, entry) { + return entry.node + .findParents() + .filter(function (parent) { + return all.indexOf(parent) === -1; + }) + .concat(all); + }, []); - // display the error in the nodes with a problem - this.errorNodes = duplicateErrors - .concat(schemaErrors) - .reduce(function expandParents (all, entry) { - // expand parents, then merge such that parents come first and - // original entries last - return entry.node - .findParents() - .filter(function (parent) { - return parentErrors.indexOf(parent) === -1; - }) - .map(function (parent) { - parentErrors.push(parent); - return { - node: parent, - child: entry.node, - error: { - message: parent.type === 'object' - ? 'Contains invalid properties' // object - : 'Contains invalid items' // array - } - }; - }) - .concat(all, [entry]); - }, []) - // TODO: dedupe the parent nodes + this.errorNodes = parents + .map(function (parent) { + return { + node: parent, + child: entry.node, + error: { + message: parent.type === 'object' + ? 'Contains invalid properties' // object + : 'Contains invalid items' // array + } + }; + }) + .concat(errorNodes) .map(function setError (entry) { entry.node.setError(entry.error, entry.child); return entry.node; From e75043e51d32719bad5423268adfe079b854ac11 Mon Sep 17 00:00:00 2001 From: James Garbutt <43081j@users.noreply.github.com> Date: Wed, 21 Feb 2018 15:06:32 +0000 Subject: [PATCH 3/3] use first node as context for parent errors --- src/js/treemode.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/js/treemode.js b/src/js/treemode.js index dac4014..5a03f30 100644 --- a/src/js/treemode.js +++ b/src/js/treemode.js @@ -436,23 +436,28 @@ treemode.validate = function () { } var errorNodes = duplicateErrors.concat(schemaErrors); - var parents = errorNodes + var parentPairs = errorNodes .reduce(function (all, entry) { return entry.node .findParents() .filter(function (parent) { - return all.indexOf(parent) === -1; + return !all.some(function (pair) { + return pair[0] === parent; + }); + }) + .map(function (parent) { + return [parent, entry.node]; }) .concat(all); }, []); - this.errorNodes = parents - .map(function (parent) { + this.errorNodes = parentPairs + .map(function (pair) { return { - node: parent, - child: entry.node, + node: pair[0], + child: pair[1], error: { - message: parent.type === 'object' + message: pair[0].type === 'object' ? 'Contains invalid properties' // object : 'Contains invalid items' // array }