Attribute

Attribute provides configurable attribute support along with attribute change events. It is designed to be augmented on to a host class, and provides the host with the ability to configure attributes to store and retrieve state, along with attribute change events.

For example, attributes added to the host can be configured:

  • With a setter function, which can be used to manipulate values passed to Attribute's Attribute#set method, before they are stored.
  • With a getter function, which can be used to manipulate stored values, before they are returned by Attribute's Attribute#get method.
  • With a validator function, to validate values before they are stored.

See the Attribute#addAttr method, for the complete set of configuration options available for attributes

.

NOTE: Most implementations will be better off extending the Base class, instead of augmenting Attribute directly. Base augments Attribute and will handle the initial configuration of attributes for derived classes, accounting for values passed into the constructor.

defined in: attribute.js

Class

Methods

  • addAttr (name, attrConfig, override) Adds an attribute with the provided configuration to the host object.
  • addAttrs (attrConfigs, initialValues) Configures a group of attributes, and sets initial values.
  • get (name) Gets the current value of the attribute.
  • getAttrs ()
  • getAttrVals ()
  • hasAttr (name) Checks if the given attribute has been added to the host.
  • removeAttr (name) Removes an attribute from the host object.
  • reset (name, opts) Resets the value of an attribute.just reset what addAttr set (not what invoker set when call new Xx(cfg))
  • set (name, value, opts) Sets the value of an attribute.

Class Detail

  • Attribute ()

    Attribute provides configurable attribute support along with attribute change events. It is designed to be augmented on to a host class, and provides the host with the ability to configure attributes to store and retrieve state, along with attribute change events.

    For example, attributes added to the host can be configured:

    • With a setter function, which can be used to manipulate values passed to Attribute's Attribute#set method, before they are stored.
    • With a getter function, which can be used to manipulate stored values, before they are returned by Attribute's Attribute#get method.
    • With a validator function, to validate values before they are stored.

    See the Attribute#addAttr method, for the complete set of configuration options available for attributes

    .

    NOTE: Most implementations will be better off extending the Base class, instead of augmenting Attribute directly. Base augments Attribute and will handle the initial configuration of attributes for derived classes, accounting for values passed into the constructor.

Methods Detail

  • addAttr (name, attrConfig, override) view source
    Adds an attribute with the provided configuration to the host object.
    Parameters
    •   name {String} attrName
    •   attrConfig {Object} The config supports the following properties
    • [ attrConfig.value ] simple object or system native object
    • [ attrConfig.valueFn ] a function which can return current attribute's default value
    • [ attrConfig.setter ] {Function(*)} call when set attribute's value pass current attribute's value as parameter if return value is not undefined,set returned value as real value
    • [ attrConfig.getter ] {Function(*)} call when get attribute's value pass current attribute's value as parameter return getter's returned value to invoker
    • [ attrConfig.validator ] {Function(*)} call before set attribute's value if return false,cancel this set action
    • [ override ] {Boolean} whether override existing attribute config ,default true
  • addAttrs (attrConfigs, initialValues) view source
    Configures a group of attributes, and sets initial values.
    Parameters
    •   attrConfigs {Object} An object with attribute name/configuration pairs.
    •   initialValues {Object} user defined initial values
  • get (name) view source
    Gets the current value of the attribute.
    Parameters
    •   name {String} attribute's name
  • getAttrs () view source
    Returns
    • un-cloned attr config collections
  • getAttrVals () view source
    Returns
    • un-cloned attr value collections
  • hasAttr (name) view source
    Checks if the given attribute has been added to the host.
    Parameters
    •   name
  • removeAttr (name) view source
    Removes an attribute from the host object.
    Parameters
    •   name
  • reset (name, opts) view source
    Resets the value of an attribute.just reset what addAttr set (not what invoker set when call new Xx(cfg))
    Parameters
    •   name {String} name of attribute
    • [ opts ] {Object} some options
    • [ opts.silent ] {Boolean} whether fire change event
  • set (name, value, opts) view source
    Sets the value of an attribute.
    Parameters
    •   name {String|Object} attribute's name or attribute name and value map
    • [ value ] attribute's value
    • [ opts ] {Object} some options
    • [ opts.silent ] {Boolean} whether fire change event
    Returns
    • {Boolean} whether pass validator
blog comments powered by Disqus
Top