Skip to content

Commit

Permalink
Fix findNodeRefsById
Browse files Browse the repository at this point in the history
  • Loading branch information
TwitchBronBron committed Oct 17, 2024
1 parent f3d450d commit 0df21e0
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 23 deletions.
30 changes: 13 additions & 17 deletions lib/components/Reftracker.bs
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,22 @@ function discover(_ = invalid)
end function)
end function

interface GetNodesByIdOptions
id as string
end interface

'@public
function getNodesById(options as GetNodesByIdOptions)
function findNodeRefsById(options as reftracker.FindNodeRefsByIdOptions)
id = options.id
results = []
' for each node in m.allNodes
' if node.id <> id
' continue for
' end if
' reftrackerId = reftracker.internal.getReftrackerId(node)
' 'build a list of keypaths for this node
' results.push({
' id: id,
' node: node,
' keypaths: m.keypathsByNodeReftrackerId[reftrackerId],
' })
' end for
for each node in m.allNodes
if node.id <> id
continue for
end if
reftrackerId = reftracker.internal.getReftrackerId(node)
'build a list of keypaths for this node
results.push({
id: id,
node: node,
keypaths: m.keypathsByNodeReftrackerId[reftrackerId],
})
end for
return results
end function

Expand Down
1 change: 1 addition & 0 deletions lib/components/Reftracker.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<interface>
<function name="discover" />
<function name="registerNodeRef" />
<function name="findNodeRefsById" />
<field id="runId" type="string" />
</interface>
<script type="text/brightscript" uri="pkg:/components/Reftracker.bs" /> <!-- bs:disable-line -->
Expand Down
18 changes: 14 additions & 4 deletions lib/source/reftrackerLib.bs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ end interface

namespace reftracker

interface FindNodeRefsByIdOptions
id as string
end interface

' Find all references to a SceneGraph node by its ID. Since multiple nodes can have the same ID, this function returns an array of results,
' where each entry includes all results for a specific node having that ID
function findNodeRefsById(id as string)
function findNodeRefsById(options as reftracker.FindNodeRefsByIdOptions)
'build the reftracker
tracker = createObject("roSGNode", "Reftracker")
'store a reference to it so it doesn't get lost
Expand All @@ -24,10 +28,16 @@ namespace reftracker
'run it
discoverPromise = tracker@.discover()

return reftracker.promises.onThen(discoverPromise, function(result, tracker)
return reftracker.promises.onThen(discoverPromise, function(result, options)
'return all nodes with the given id
return tracker@.findNodeRefsById(id)
end function, tracker)
result = options.tracker@.findNodeRefsById({
id: options.id
})
return result
end function, {
tracker: tracker,
id: options.id
})
end function
end namespace

Expand Down
6 changes: 4 additions & 2 deletions test-app/components/MainScene.bs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ sub init()
m.arr = [
m.mainLabel
]

reftracker.promises.chain(reftracker.findNodeRefsById("mainLabel")).then(function(result, node)
promise = reftracker.findNodeRefsById({
id: "mainLabel"
})
reftracker.promises.chain(promise).then(function(result)
print result
end function)
end sub

0 comments on commit 0df21e0

Please sign in to comment.