Skip to content

Commit

Permalink
Fix many bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
TwitchBronBron committed Oct 17, 2024
1 parent b0dddf0 commit befbd59
Show file tree
Hide file tree
Showing 13 changed files with 193 additions and 82 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
]
},
{
"name": "Debug test-project",
"name": "Debug test app",
"type": "brightscript",
"request": "launch",
"rootDir": "${workspaceFolder}/out/dist",
Expand Down
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
58 changes: 39 additions & 19 deletions lib/components/Reftracker.bs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/components/Reftracker.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
<function name="registerNodeRef" />
<field id="runId" type="string" />
</interface>
<script type="text/brightscript" uri="pkg:/components/Reftracker.bs" />
<script type="text/brightscript" uri="pkg:/components/Reftracker.bs" /> <!-- bs:disable-line -->
</component>
Loading

0 comments on commit befbd59

Please sign in to comment.