Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Level 11

To Whom the ObserveField() Tolls ?

I am struggling to understand the functioning of observeField(). The documentation is (un)usually sloppy, mumbling:
"ifSGNodeField.observeField()" wrote:

observeField(fieldName as String, function as String)
function - The function to call when the field value changes
First Form
This form calls the function specified by function when the subject node field specified by fieldName changes.

The problem is that the mis-labeled^ "function" above is not really a Function, it is a String. And as such it has to get resolved in some context to a B/S function proper. Whose context does that string get looked up in - when and how? 

Note that while "fieldName" and "function" above both are Strings, they get resolved (looked up) in different contexts - fieldName will be looked up within the component to which observeField() is called. E.g. say calling
Noid.observeField("visible", "avoid")
will put a contract on changes of Noid.visible - however the function avoid() that will be called may not be part of the Noid component. Or it may be. There might be different "avoid()" functions in different components. My point is, the name resolution works differently for "avoid" than for "visible".

Herefore i ask - how, when and where is the callback function looked up?

(^) it should have been functionName. If the difference between "function" and "function name" is not apparent to someone, it might be time to re-visit the White Knight's song as an adult (yes, Lewis Carroll is very meta)
0 Kudos
1 Reply
Level 11

Re: To Whom the ObserveField() Tolls ?

I see a few days later doco page was updated to use functionName and add the following cryptic sentence:
"First Form" wrote:

This form calls the function specified by functionName when the subject node field specified by fieldName changes. The function called must be in the scope of the current component. [...]

Eh? <scratches head> What does that even mean, who is the "current component"?

  • the one on which observeField() was called,

  • the one who is causing the field to get updated (directly or as part of a cascade),

  • the one who put the contract (there might not be one! read below) ... 

Which reminds me again Alice: the difference between the song, how the song is called, the name of the song and how the name of the song is called.

I would venture guessing it is not "Noid" in the above example `Noid.observeField("visible", "avoid")` because in other place it was said one can notify one component for changes in another, i.e. "visible" (field owned by Noid) and "avoid" (event handler) should be resolvable to different nodes, potentially. 

Does it mean "in the exact scope (interpreter? thread?) where observeField() is being called - when observeField() is being called"? But then the whole "The function called must be in the scope of the current component" is a wrong thing to say, because if the call is made from the main() thread, there is no "current component" at any point! I.e. i could ostensibly call `Noid.observeField("visible", "avoid")` in the main thread, because SG nodes are visible (thread-safed...-saved?) between threads. Whose function avoid() will be called then?
0 Kudos