When/How does an expression binding get evaluated?

In the last episode of "Under the hood" we learnt that everything [1] in Perspective runs on the GW

In order to better understand the technical details of this, I want to ask about the mechanism that evaluates a binding (and then ask about interactions with event scripts)

Say that we have a label object that has its fill property bound to a tag via a simple expression like:

if(ExternalBoolTag, "#00FF00","#FF0000")

From an HMI user's point of view, when the value of "ExternalBoolTag" changes between True and False, the expression returns Green or Red RGB colors. And the Fill color of the label receives this value and the label changes visually to match the result.

But I want to understand the action from a "GW behind the scenes programming" point of view.

The following is my interpretation of how this could work in the GW [7]:

  • The ExternalBoolTag is an object sitting in a chunk of memory in the GW
  • The label is another object sitting a different chunk of memory.
  • The expression binding is another object that sits somewhere else, and is registered with both the tag and label via some sort of hooks or lists of objects or list of object pairs.

When something writes a new value into ExternalBoolTag [2]:

  1. It triggers an action that iterates over all the different things that are registered to that tag. One of the registered items is the expression binding of the label.
  2. When the expression binding is encountered, it kicks off a process that evaluates the expression with the current value of ExternalBoolTag
  3. The evaluation process then writes the color value into the fill property of the label object
  4. The writing of fill property [2] triggers another process that causes the Perspective module to re-render the label with the new fill color, and send it off to the Perspective session that is displaying it.

So from a mile high point of view, is the above process somewhere in the realm of what actually happens when evaluating an expression binding? And that everything happens asynchronously, triggered by the write into ExternalBoolTag?

Adding on to this, if the label had a user triggered Event attached to it, that then ran a script that wrote the value of ExternalBoolTag, would the following sequence also be basically true?

  1. User clicks on the label
  2. The Perspective session detects the click and sends a message back to the GW saying that a click was detected on the label [3]
  3. The GW [4] invokes a script runner to execute the script attached to the event.
  4. During the execution of the script, a new value is written to ExternalBoolTag
  5. The script running finishes executing the script.

If this is also basically correct, my question is when step 4 is reached, where ExternalBoolTag is written, does this asynchronously [5] kick off the previously noted expression binding sequence? Or does the Event script need to terminate before the Expression binding gets evaluated? My gut feeling says "asynchronous execution" due to an overall event driven programming model, but I could be wrong.

One implication of this is data coherence in the event script. If the script both sets the value of ExternalBoolTag, and also reads the value of the label's fill color [6] then depending on the programming model the value of the fill color that was read may or may not be up to date.


[1] For differing values of "everything"
[2] Not sure if the process is triggered on a simple write, or on a write of a different value.
[3] Or the session just sends the mouse co-ordinates back to the GW which figures itself which object was clicked. That's probably a React implementation detail.
[4] Probably the "Perspective module" in the GW might be more accurate
[5] As asynchronously as can be with a CPU with a finite number of cores.
[6] Yes, a very stupid thing to do.
[7] In my descriptions I may be using some terms that have a specific meaning in a programming environment in a very loose manner. So take it all with a bag of salt (a grain of salt is too small in this case!)

This matches my understanding.

Pretty sure your gut is correct.