@phosphor/properties

  • Version 1.1.3
  • Published
  • 13.2 kB
  • No dependencies
  • BSD-3-Clause license

Install

npm i @phosphor/properties
yarn add @phosphor/properties
pnpm add @phosphor/properties

Overview

PhosphorJS - Attached Properties

Index

Classes

class AttachedProperty

class AttachedProperty<T, U> {}
  • A class which attaches a value to an external object.

    #### 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.

constructor

constructor(options: AttachedProperty.IOptions<T, U>);
  • Construct a new attached property.

    Parameter options

    The options for initializing the property.

property name

readonly name: string;
  • The human readable name for the property.

method coerce

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

    Parameter owner

    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.

method get

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

    Parameter owner

    The property owner of interest.

    Returns

    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.

method set

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

    Parameter owner

    The property owner of interest.

    Parameter value

    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.

Namespaces

namespace AttachedProperty

namespace AttachedProperty {}
  • The namespace for the AttachedProperty class statics.

function clearData

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

    Parameter owner

    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.

interface IOptions

interface IOptions<T, U> {}
  • The options object used to initialize an attached property.

property changed

changed?: (owner: T, oldValue: U, newValue: U) => 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.

property coerce

coerce?: (owner: T, value: U) => 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.

property compare

compare?: (oldValue: U, newValue: U) => 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.

property create

create: (owner: T) => 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.

property name

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.

Package Files (1)

Dependencies (0)

No dependencies.

Dev Dependencies (14)

Peer Dependencies (0)

No peer dependencies.

Badge

To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@phosphor/properties.

  • Markdown
    [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@phosphor/properties)
  • HTML
    <a href="https://www.jsdocs.io/package/@phosphor/properties"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>