class Binding
A class that represents a property binding.
class Binding<T = any>;
Description
A binding connects an object (an instance of ObservableObject) with one of the properties of one of another object: either a specified source object, or one of the target object’s containing (attached) objects. Bindings can be used to update properties on the target object, keeping the bound property in sync with the original property.
For example, given an object A with property p, a binding can be used on an attached object B to update target property q. When the value of p changes, the same value is set on q immediately. This is considered a one-way data binding, since direct updates on property q don’t affect the source property p at all.
To make bindings work across a chain — or technically, a tree structure — of attached objects, bindings keep track of object attachments to the target object (i.e. object B) all the way up the chain, to find a matching source property. Therefore, a binding on C, itself attached from B, may also read property values from A.
Instead of a single source property, bindings can also specify a source property ‘path’ using dots to separate property names: a path of p.foo.bar first watches p, then (if p refers to an object) its property foo, and so on — going first up the tree structure to find the object containing p, and then down again to find the rest.
As a concrete example, a binding can be used to update the text property of a UIText view, with the value of a string property someText of the activity. Or perhaps the property name of a user object referenced by the activity (see example below). Whenever the data in the activity changes, so does the text.
Creating bindings — To create a binding, use the Binding constructor to bind a single property, use methods like Binding.all(), Binding.any(), or Binding.none() to combine bindings, or use the Binding.fmt() function to bind a string composed using a format string and one or more embedded bindings.
Applying bindings — To use a binding, pass it to a UI view builder function, e.g. UI.Text(v.bind("someText")). To apply a binding to any other observable object directly, use the ObservableObject.observe() method.
Adding transformations — To convert the value of the original property, or to combine multiple bindings using boolean operations (and/or), use one of the Binding methods such as map(), Binding.all(), and Binding.any().
Constructor
new Binding()
Creates a new binding for given property and default value.
Type members
interface Binding.BindProperty static
Creates a new binding to observe the specified property.type Binding.Options static
Options that can be passed to the Binding constructor.type Binding.BoundPath static
Type definition for a property path.type Binding.BoundPathValue static
Type definition for a property value, based on a property path.
Static members
Binding.from() static
Creates a new binding using the provided binding, or a new binding that encapsulates the provided value.Binding.all() static
Creates a new binding that combines multiple bindings using AND semantics.Binding.any() static
Creates a new binding that combines multiple bindings using OR semantics.Binding.none() static
Creates a new binding that returns true if none of the combined bindings are truthy.Binding.equal() static
Creates a new binding that returns true if all combined binding values are equal.Binding.combine() static
Creates a new binding by combining multiple bindings into a single value.Binding.observe() static
Creates a new binding that references a property of the provided object.Binding.fmt() static
Creates a new binding for a string-formatted value.
Instance members
clone() protected
Creates a copy of this binding.bind
Creates a new binding to observe the specified property from any (currently bound) object.bindAll()
Creates a new binding to observe the specified properties, combining them using AND semantics.bindAny()
Creates a new binding to observe the specified properties, combining them using OR semantics.bindNone()
Creates a new binding to observe the specified properties, returning true if none are truthy.string()
Transforms the bound value to a string, optionally using the specified format.not()
Transforms the bound value to a boolean, and negates it.and()
Combines this binding with another using AND semantics.or()
Combines this binding with another using OR semantics.map()
Transforms the bound value, using the provided function.then()
Transforms the bound value to either one of the specified values (or undefined).else()
Transforms the bound value to the specified value, if the bound value is equal to false.equals()
Transforms to a boolean, true if the bound value exactly equals one of the specified values.notEquals()
Transforms to a boolean, true if the bound value doesn’t equal any of the specified values exactly.lt()
Transforms to a boolean, true if the bound value is less than a literal value.lte()
Transforms to a boolean, true if the bound value is less than or equal to a literal value.gt()
Transforms to a boolean, true if the bound value is greater than a literal value.gte()
Transforms to a boolean, true if the bound value is greater than or equal to a literal value.toString()
Returns a description of this binding, including its original source path, if any.
