diff --git a/.vscode/launch.json b/.vscode/launch.json index c5e69ae..7c7488d 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -24,7 +24,7 @@ ] }, { - "name": "Debug test-project", + "name": "Debug test app", "type": "brightscript", "request": "launch", "rootDir": "${workspaceFolder}/out/dist", diff --git a/.vscode/settings.json b/.vscode/settings.json index 3a12e80..c2886cd 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -20,5 +20,5 @@ "typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets": false, "files.trimTrailingWhitespace": true, "typescript.tsdk": "node_modules\\typescript\\lib", - "brightscript.bsdk": "embedded" + "brightscript.bsdk": "1.0.0-alpha.39" } diff --git a/.vscode/tasks.json b/.vscode/tasks.json index cb8641a..6100116 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -13,7 +13,7 @@ { "label": "build-test-app", "type": "shell", - "command": "cd test-project && npx bsc", + "command": "cd test-app && npx bsc", "group": { "kind": "test", "isDefault": true diff --git a/lib/components/Reftracker.bs b/lib/components/Reftracker.bs index 59dafd0..752e4c9 100644 --- a/lib/components/Reftracker.bs +++ b/lib/components/Reftracker.bs @@ -32,11 +32,15 @@ function discover(_ = invalid) end for 'process the nodes one-by-one - return promises.onThen(processNextNode(), function(result) - print "done processing nodes" + return promises.onThen(processNodes(), function(result) + printNodes() end function) end function +function printNodes() + print FormatJson(m.keypathsByNodeReftrackerId) +end function + 'Register a reference to a node so we can process it later. This function registerNodeRef(keypath as string, node as roSGNode) reftrackerId = reftracker.internal.getReftrackerId(node) @@ -61,34 +65,50 @@ function registerNodeRef(keypath as string, node as roSGNode) m.keypathsByNodeReftrackerId[reftrackerId].push(keypath) end function -function processNextNode() +function processNodes() 'if we have no more nodes, we are done! if m.nodeQueue.count() = 0 + reftracker.internal.writeLog("All nodes have been processed. Exiting node process loop") return promises.resolve(invalid) end if - nodeQueueItem = m.nodeQueue.pop() - - print `reftracker: processing node ${nodeQueueItem.keypath}<${nodeQueueItem.node.subtype()}>` - - return promises.chain(promises.resolve(true), nodeQueueItem).then(function(result, queueItem as NodeQueueItem) - 'if this node supports reftracker functionality, process the node's internal `m` - if (nodeQueueItem.node as dynamic).reftrackerEnabled then - return nodeQueueItem.node@.reftracker_internal_execute({ command: "discover", reftracker: m.top }) + queueItem = m.nodeQueue.pop() as NodeQueueItem + + reftracker.internal.writeLog("processing node", queueItem.keypath, queueItem.node.subtype()) + + 'if this node supports reftracker functionality, process the node's internal `m` + return promises.chain(promises.resolve(true), queueItem).then(function(result, queueItem as NodeQueueItem) + if (queueItem.node as dynamic).reftrackerEnabled then + reftracker.internal.writeLog("processing node's internal m properties", queueItem.keypath, queueItem.node.subtype()) + return queueItem.node@.reftracker_internal_execute({ + command: "discover", + reftracker: m.top, + keypath: queueItem.keypath + }) + else + reftracker.internal.writeLog("node does not support reftracker intraspection", queueItem.keypath, queueItem.node.subtype()) end if - end function).then(function(result, nodeQueueItem as NodeQueueItem) + 'add all public fields to a list of stuff to work on - for each field in nodeQueueItem.node.getFields() - value = nodeQueueItem.node[field] - reftracker.internal.registerWorkItem(m.top, `${nodeQueueItem.keypath}.${field}`, value) + end function).then(function(result, queueItem as NodeQueueItem) + reftracker.internal.writeLog("processing node fields", queueItem.keypath, queueItem.node.subtype()) + for each fieldName in queueItem.node.getFields() + value = queueItem.node[fieldName] + reftracker.internal.registerWorkItem(queueItem.keypath, fieldName, value) end for 'now process this data (it will run async and process in chunks until all are finished) - return reftracker.internal.processWorkItems(m.top) - - end function).then(function(result, nodeQueueItem as NodeQueueItem) + return reftracker.internal.processWorkItems({ + reftracker: m.top, + keypath: queueItem.keypath + }) - return processNextNode() + 'now process the next node + end function).then(function(result, queueItem as NodeQueueItem) + reftracker.internal.writeLog("Processing next node") + return processNodes() + end function).catch(function(error, _) + print FormatJson(error) end function).toPromise() end function diff --git a/lib/components/Reftracker.xml b/lib/components/Reftracker.xml index 6f4a387..fb02dde 100644 --- a/lib/components/Reftracker.xml +++ b/lib/components/Reftracker.xml @@ -4,5 +4,5 @@ -