highlights and values working

This commit is contained in:
Luis Fernando Molina committed 2020-06-16 19:21:38 +02:00
1 parent 1ed6a48488
commit 6796745980
10 files changed
+233 -140

No files matched your search

+47
View File
@@ -0,0 +1,47 @@
/*
This function scans a node hiriatchy recursively and creates a Map by Id of all the nodes of it.
*/
function getHiriarchyMap (rootNode) {
let hiriatchyMap = new Map()
evalNode(rootNode)
return hiriatchyMap
function evalNode (node) {
if (node === undefined) { return }
hiriatchyMap.set(node.id, node)
/* Now we go down through all this node children */
let nodeDefinition = APP_SCHEMA_MAP.get(node.type)
if (nodeDefinition === undefined) { return }
if (nodeDefinition.properties !== undefined) {
let previousPropertyName // Since there are cases where there are many properties with the same name,because they can hold nodes of different types but only one at the time, we have to avoind counting each property of those as individual children.
for (let i = 0; i < nodeDefinition.properties.length; i++) {
let property = nodeDefinition.properties[i]
switch (property.type) {
case 'node': {
if (property.name !== previousPropertyName) {
if (node[property.name] !== undefined) {
evalNode(node[property.name])
}
previousPropertyName = property.name
}
break
}
case 'array': {
if (node[property.name] !== undefined) {
let nodePropertyArray = node[property.name]
for (let m = 0; m < nodePropertyArray.length; m++) {
evalNode(nodePropertyArray[m])
}
}
break
}
}
}
}
}
}
-45
View File
@@ -1,45 +0,0 @@
/*
This function scans a node hiriatchy recursively. At each node it calls the callback
provided with the corresponfing value of the array.
*/
function evalNode (node, array, index, callback) {
if (node === undefined) { return }
if (array === undefined) { return }
if (index === undefined) { return }
if (callback === undefined) { return }
callback(node, array[index])
/* Now we go down through all this node children */
let nodeDefinition = APP_SCHEMA_MAP.get(node.type)
if (nodeDefinition === undefined) { return }
if (nodeDefinition.properties !== undefined) {
let previousPropertyName // Since there are cases where there are many properties with the same name,because they can hold nodes of different types but only one at the time, we have to avoind counting each property of those as individual children.
for (let i = 0; i < nodeDefinition.properties.length; i++) {
let property = nodeDefinition.properties[i]
switch (property.type) {
case 'node': {
if (property.name !== previousPropertyName) {
if (node[property.name] !== undefined) {
evalNode(node[property.name], array, index + 1, callback)
}
previousPropertyName = property.name
}
break
}
case 'array': {
if (node[property.name] !== undefined) {
let nodePropertyArray = node[property.name]
for (let m = 0; m < nodePropertyArray.length; m++) {
evalNode(nodePropertyArray[m], array, index + 1, callback)
}
}
break
}
}
}
}
}