Intro to bindables - xshley/binding GitHub Wiki

Examples:

Normal Bindable

We can create our reactive data source (Bindable).

final Bindable<Float> bindable = new Bindable<>(5f);

Binding bindables

We can also create a bindable which is bound to another bindable. This then allows any changes made to the first bindable propagate to the 2nd bindable.

final Bindable<Float> bindable2 = bindable.getBoundCopy();

Weak bindable copy

We can also make a bindable that's "Weakly" bound to the bindable, which means any changes made on this weakly bound bindable will not propagate to the other bindable, but any changes made on the other bindable will propagate to this one.

final Bindable<Float> watcher = bindable.getWeakCopy();

Unbound bindable copy

We can also get a Unbound Copy which has no binding and is the same as just a copy of the bindable.

final Bindable<Float> copy = bindable.getBoundCopy();

Strong bindable copy

We can also create a "Strong" Bindable which is just a bindable with a default value that we can always reset back to.

final StrongBindable<Float> bindable2 = new StrongBindable<>(5.0f);

Binding a bindable

You can also bind a value directly through #weakBind or #bindTo.

bindable2.bindTo(bindable1);
⚠️ **GitHub.com Fallback** ⚠️