Globals

There are situations where having a global state accessible to any part of the UI, regardless of whether they have their own binding context, is necessary. This is particularly useful, for instance, when determining if the main menu is open or closed, and when you need binding in the markup that references these global context properties.

The global context is always associated with a binding identifier (bid) of 0. It is automatically established during the initialization process of the binding engine. Consequently, you will consistently have at least one binding context in your application, which is the global context.

In binding expressions, you can reference a property within the global context by utilizing the $globals keyword. Please consider the following example:

<input value.bind="$globals.message">
<div>Value in globals: ${$globals.message}</div>

You can get and set global properties using the binding data manager.

// set the message property
await crs.binding.data.setProperty(crs.binding.$global, "message", "Hello World")

// get the value of the message property
result = await crs.binding.data.getProperty(crs.binding.$global, "message")