Bindable Properties

Jancy supports bindable properties which automatically notify subscribers when they change. Bindable properties play crucial role in the reactive programming.

Simple bindable property declaration syntax:

int autoget bindable property g_simpleProp;

g_simpleProp.set(int x) {
    if (x == m_value)
        return;

    m_value = x;
    m_onChanged(); // name of compiler-generated event is 'm_onChanged'
}

onPropChanged() {
    // ...
}

int main() {
    // ...

    bindingof(g_simpleProp) += onPropChanged;
    g_simpleProp = 100; // onPropChanged will get called
    g_simpleProp = 100; // onPropChanged will NOT get called

    // ...
}

Similar property declared using full syntax:

property g_prop {
    autoget int m_x; // 'autoget' field implicitly makes property 'autoget'
    bindable event m_e(); //'bindable' event implicitly makes property 'bindable'

    set(int x) {
        m_x = x;
        m_e();
    }
}

Bindable Data

Jancy offers fully compiler-generated properties: getter, setter, back-up field and on-change event are all generated by the Jancy compiler. These degenerate properties are designed to track data changes: they can be used as variables or fields that automatically notify subscribers when they change.

int bindable g_data;

onDataChanged() {
    // ...
}

int main() {
    // ...

    bindingof(g_data) += onDataChanged;
    g_data = 100; // onDataChanged will get called
    g_data = 100; // onDataChanged will NOT get called

    // ...
}