Skip to content

Commit

Permalink
Fix bug not registering nodes from callfunc
Browse files Browse the repository at this point in the history
  • Loading branch information
TwitchBronBron committed Oct 17, 2024
1 parent 5a05184 commit 9dae288
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 22 deletions.
20 changes: 11 additions & 9 deletions lib/components/Reftracker.bs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function discover(_ = invalid)
end function

function printNodes()
print FormatJson(m.keypathsByNodeReftrackerId)
print m.nodesByKeypath
end function

'Register a reference to a node so we can process it later. This
Expand Down Expand Up @@ -84,13 +84,15 @@ function processNodes()

'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
})
reftracker.internal.writeLog("processing node's internal m properties", queueItem.keypath, queueItem.node.subtype())
promise = queueItem.node@.reftracker_internal_execute({
command: "discover",
reftracker: m.top,
keypath: queueItem.keypath
})

if promise <> invalid then
return promise
else
reftracker.internal.writeLog("node does not support reftracker intraspection", queueItem.keypath, queueItem.node.subtype())
end if
Expand All @@ -101,7 +103,7 @@ function processNodes()
children = queueItem.node.getChildren(-1, 0) as roSGNode[]
reftracker.internal.writeLog(`registering ${children.count()} children of node`, queueItem.keypath, queueItem.node.subtype())
for i = 0 to children.Count() - 1
registerNodeRef(queueItem.keypath, i.ToStr(), children[i])
registerNodeRef(queueItem.keypath, `getChild(${i})`, children[i])
end for

'register work items for each field on the node
Expand Down
3 changes: 2 additions & 1 deletion lib/source/reftrackerLib.bs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ namespace reftracker.internal
'if this is a node, push register it with the reftracker to be processed later
if itemType = "roSGNode"
writeLog("item is a node. pushing to node queue", itemKeypath, itemType)
options.reftracker@.registerNodeRef(item)
options.reftracker@.registerNodeRef(options.keypath, workItem.key, item)
else if itemType = "roArray"
if isProcessed(item)
writeLog("item is an array and already processed. Skipping", itemKeypath, itemType)
Expand Down Expand Up @@ -248,6 +248,7 @@ namespace reftracker.internal

interface WorkQueueItem
keypath as string
key as string
item as dynamic
end interface

Expand Down
12 changes: 0 additions & 12 deletions src/Plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,6 @@ export class Plugin implements CompilerPlugin {
]
)
);
//add a new interface field indicating this function is available
editor.arrayPush(
file.ast.component!.api.fields,
new SGField(
{ text: 'field', range: util.createRange(0, 0, 0, 99) },
[
createSGAttribute('id', 'reftrackerEnabled'),
createSGAttribute('type', 'boolean'),
createSGAttribute('value', 'true')
]
)
);

//inject the script
editor.arrayPush(
Expand Down
4 changes: 4 additions & 0 deletions test-app/components/MainScene.bs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ sub init()
'make the text really big
m.mainLabel.font.size = 100

m.arr = [
m.mainLabel
]

promises.chain(reftracker.findNodeById("bob")).then(function(result, node)
print "found node"
end function)
Expand Down

0 comments on commit 9dae288

Please sign in to comment.