Binding

class Binding

Component property binding base class.

Bindings should be created using the bind and bindf functions, and used as a property of the object passed to Component.with.

Constructor

(source?: string, defaultValue?: any, ignoreUnbound?: boolean): Binding

.isBinding() static

(value: any): value is Binding

Returns true if given value is an instance of Binding.

.isComponentBinding()

(): true

Method for duck typing, always returns true.

.id

string

Unique ID for this binding.

.propertyName

string

Name of the property that should be observed for this binding (highest level only, does not include names of nested properties or keys).

.bindings

readonly Binding[]

Nested bindings, if any (e.g. for string format bindings, see bindf).

.parent

Binding

Parent binding, if any (e.g. for nested bindings in string format bindings).

.ignoreUnbound

boolean

Set to true to ignore this binding when a component is added to a composite parent that has not been preset with this binding (to avoid the ‘Binding not found for X’ error), which can happen if a component is not added through @compose but as a regular child object using @managedChild.

.addFilter()

(fmt: string): this

Add a filter to this binding, which transforms values to a specific type or format. These can be chained by adding multiple filters in order of execution.

Filters can also be specified after the | (pipe) separator in string argument given to the Binding constructor, or bind function.

Available bindings include:

  • s, str, or string: convert non-undefined values to a string using the String(...) function.

  • n, num, or number: convert non-undefined values to a floating-point number using the parseFloat(...) function.

  • i, int, or integer: convert values to whole numbers using the Math.round(...) function. Undefined values are converted to 0.

  • dec(1), dec(2), dec(3) etc.: convert values to decimal numbers as strings, with given number of fixed decimals.

  • tt or tt(type): translate values using the tt function (i18n).

  • ? or !!, not? or !: convert values to boolean, applying boolean NOT for ! and not?, and NOT-NOT for ? and !!.

  • or(...): use given string if value is undefined or a blank string; the string cannot contain a } character.

  • then(...): use given string if value is NOT undefined or a blank string, otherwise undefined; the string cannot contain a } character.

  • uniq: leave only unique values in an array, and discard undefined values

  • blank or _: output an empty string, but make the unfiltered value available for the #{…} pattern in bindf.

.match()

(...values: any[]): this

Add a filter to this binding to compare the bound value to the given value(s), the result is always either true (at least one match) or false (none match).

.nonMatch()

(...values: any[]): this

Add a filter to this binding to compare the bound value to the given value(s), the result is always either true (none match) or false (at least one match).

.filters static

{ [id: string]: (v: any, ...args: any[]) => any; }

List of applicable filters, new filters may be added here.


Binding.Type

Binding type (duck typed).