sheetaloza
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2016
04:48 AM
singleton into global scope
I am trying to add singleton object into globalScope to use it across the app (scene graph). While adding object into globalScope I can see that it is only doing shallow copy but deep copy. My object looks like this
I have created global variable in main.brs
And then initializing this singleton Object in first (parent) scene.
NOTE: I can access property values but not the functions. Function defined in the singleton object are treated as properties and underlying structure is NEVER copied.
I have created global variable in main.brs
And then initializing this singleton Object in first (parent) scene.
if m.global.singletonObject = invalid then
singletonObject = {
init: function()
m.counter = 0
m.childObject = invalid
end function
doSomething: function()
print "doing something"
end function
}
singletonObject.init()
print singletonObject
m.global.addFields({"singletonObject": singletonObject})
'after adding everything in the global scope, all the prop and function of singletonObject are invalid.
print m.global.singletonObject
end if
return m.global.singletonObject
NOTE: I can access property values but not the functions. Function defined in the singleton object are treated as properties and underlying structure is NEVER copied.
1 REPLY 1
EnTerr
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2016
12:04 PM
Re: singleton into global scope
True to form - node field assignments get deep copied and Brightscript first-class functions are NOT supported by Roku scenography.
See also https://forums.roku.com/viewtopic.php?f=34&t=95412
See also https://forums.roku.com/viewtopic.php?f=34&t=95412