The options object used to initialize an attached property.

interface IOptions<T, U> {
    changed?: ((owner, oldValue, newValue) => void);
    coerce?: ((owner, value) => U);
    compare?: ((oldValue, newValue) => boolean);
    create: ((owner) => U);
    name: string;
}

Type Parameters

  • T
  • U

Properties

changed?: ((owner, oldValue, newValue) => void)

A function called when the property value has changed.

Notes

This will be invoked when the property value is changed and the comparator indicates that the old value is not equal to the new value.

This will not be called for the initial default value.

Type declaration

    • (owner, oldValue, newValue): void
    • Parameters

      • owner: T
      • oldValue: U
      • newValue: U

      Returns void

coerce?: ((owner, value) => U)

A function used to coerce a supplied value into the final value.

Notes

This will be called whenever the property value is changed, or when the property is explicitly coerced. The return value will be used as the final value of the property.

This will not be called for the initial default value.

Type declaration

    • (owner, value): U
    • Parameters

      • owner: T
      • value: U

      Returns U

compare?: ((oldValue, newValue) => boolean)

A function used to compare two values for equality.

Notes

This is called to determine if the property value has changed. It should return true if the given values are equivalent, or false if they are different.

If this is not provided, it defaults to the === operator.

Type declaration

    • (oldValue, newValue): boolean
    • Parameters

      • oldValue: U
      • newValue: U

      Returns boolean

create: ((owner) => U)

A factory function used to create the default property value.

Notes

This will be called whenever the property value is required, but has not yet been set for a given owner.

Type declaration

    • (owner): U
    • Parameters

      • owner: T

      Returns U

name: string

The human readable name for the property.

Notes

By convention, this should be the same as the name used to define the public accessor for the property value.

This does not have an effect on the property lookup behavior. Multiple properties may share the same name without conflict.