Options
All
  • Public
  • Public/Protected
  • All
Menu

Class AttachedProperty<T, U>

A class which attaches a value to an external object. The namespace for the AttachedProperty class statics.

Notes

Attached properties are used to extend the state of an object with semantic data from an unrelated class. They also encapsulate value creation, coercion, and notification.

Because attached property values are stored in a hash table, which in turn is stored in a WeakMap keyed on the owner object, there is non-trivial storage overhead involved in their use. The pattern is therefore best used for the storage of rare data.

Type parameters

  • T

  • U

Hierarchy

  • AttachedProperty

Index

Constructors

constructor

Properties

Private _changed

_changed: function | null

Private _coerce

_coerce: function | null

Private _compare

_compare: function | null

Private _create

_create: function

Type declaration

    • (owner: T): U
    • Parameters

      • owner: T

      Returns U

Private _pid

_pid: string = Private.nextPID()

name

name: string

The human readable name for the property.

Methods

Private _coerceValue

  • _coerceValue(owner: T, value: U): U
  • Coerce the value for the given owner.

    Parameters

    • owner: T
    • value: U

    Returns U

Private _compareValue

  • _compareValue(oldValue: U, newValue: U): boolean
  • Compare the old value and new value for equality.

    Parameters

    • oldValue: U
    • newValue: U

    Returns boolean

Private _createValue

  • _createValue(owner: T): U
  • Get or create the default value for the given owner.

    Parameters

    • owner: T

    Returns U

Private _maybeNotify

  • _maybeNotify(owner: T, oldValue: U, newValue: U): void
  • Run the change notification if the given values are different.

    Parameters

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

    Returns void

coerce

  • coerce(owner: T): void
  • Explicitly coerce the current property value for a given owner.

    Parameters

    • owner: T

      The property owner of interest.

      Notes

      If the value has not yet been set, the default value will be computed and used as the previous value for the comparison.

    Returns void

get

  • get(owner: T): U
  • Get the current value of the property for a given owner.

    Parameters

    • owner: T

      The property owner of interest.

    Returns U

    The current value of the property.

    Notes

    If the value has not yet been set, the default value will be computed and assigned as the current value of the property.

set

  • set(owner: T, value: U): void
  • Set the current value of the property for a given owner.

    Parameters

    • owner: T

      The property owner of interest.

    • value: U

      The value for the property.

      Notes

      If the value has not yet been set, the default value will be computed and used as the previous value for the comparison.

    Returns void

Static clearData

  • clearData(owner: any): void
  • Clear the stored property data for the given owner.

    Parameters

    • owner: any

      The property owner of interest.

      Notes

      This will clear all property values for the owner, but it will not run the change notification for any of the properties.

    Returns void

Generated using TypeDoc