This page is part of the External (Extended) Documentation
Propagation of changes across the application's data model
Data models used in interactive applications, such as those written for terminals and other client software, are often denormalized - especially due to a degree of redundancy. Such redundancy is allowable in heterogeneous architectures for optimization purposes, provided that increased attention is paid to maintaining consistency of the data. In redundant data models, values are dependent on each other. To maintain the data model consistency, they must be automatically recalculated and updated when their master values change. And the quicker such recalculation is performed, the "smoother" is the user experience.
The typical illustration of such behavior is a classical MVC ("model-view-controller") user application. It has the presentation logic - the "V", which contains some variables - such as fields on a user interface form. These fields are logically connected with the underlying business model - the "M", which contains its own variables that the "V" variables depend on. Changes in the "M" data set can be as well induced by external sources. In this architecture, a vital task of the "C" - controller - is the timely propagation of any changes across the entire application's data model.
This controller logic might take expensive efforts to develop and maintain.
Quokka approach
The Quokka platform helps to address the above-stated problem in an elegant manner. You don't have to keep track of all places in the application code where data dependencies can occur and to write extra code that updates values in those places. Instead, you are encouraged to think in terms of a constant "data flow" rather than of "copying values" from time to time. When specifying dependencies between properties of elements, you should think of this as of designing your data flow. You will design it in a declarative style when coding your properties. It will tell the system that it must automatically refresh values of properties when their source values have been changed by whatever means. The Quokka platform will take care of the most prompt updating of all dependent properties. This approach is referred to as reactive property references, or, more generally, as reactivity.
The syntax
A property can be assigned from another property not by value but by reference, with the reactivity syntax, which uses double curly braces:
[public] <ClassName> propName: {{another_prop_reference}}
The above simple statement establishes the "data flow" from another_prop_reference, which is referenced by the curly braces, to propName, which references it. This reactive reference means that as soon as the value of the another_prop_reference property changes, so will automatically do the value of propName.
Example
In the example below, we will dynamically calculate an item's price based on the US dollar rate, which can be updated from an external source.
def Page main
// suppose our item cost is $39.99
Number priceUSD: 39.99
// this is just an initial value; it is supposed to change dynamically
Number rateUSD: 58.00
// this control displays the price which is automatically updated as the USD rate (or the price in dollars) changes somehow
TextBox itemPrice: {{priceUSD * rateUSD}}