Merge pull request #510 from crispthinking/parent-error-cache

cache parent errors
This commit is contained in:
Jos de Jong 2018-02-25 17:31:23 +01:00 committed by GitHub
commit 4e6f43412c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 29 additions and 22 deletions

View File

@ -435,28 +435,35 @@ treemode.validate = function () {
} }
} }
// display the error in the nodes with a problem var errorNodes = duplicateErrors.concat(schemaErrors);
this.errorNodes = duplicateErrors var parentPairs = errorNodes
.concat(schemaErrors) .reduce(function (all, entry) {
.reduce(function expandParents (all, entry) {
// expand parents, then merge such that parents come first and
// original entries last
return entry.node return entry.node
.findParents() .findParents()
.filter(function (parent) {
return !all.some(function (pair) {
return pair[0] === parent;
});
})
.map(function (parent) { .map(function (parent) {
return [parent, entry.node];
})
.concat(all);
}, []);
this.errorNodes = parentPairs
.map(function (pair) {
return { return {
node: parent, node: pair[0],
child: entry.node, child: pair[1],
error: { error: {
message: parent.type === 'object' message: pair[0].type === 'object'
? 'Contains invalid properties' // object ? 'Contains invalid properties' // object
: 'Contains invalid items' // array : 'Contains invalid items' // array
} }
}; };
}) })
.concat(all, [entry]); .concat(errorNodes)
}, [])
// TODO: dedupe the parent nodes
.map(function setError (entry) { .map(function setError (entry) {
entry.node.setError(entry.error, entry.child); entry.node.setError(entry.error, entry.child);
return entry.node; return entry.node;