Classdesc

An expanded version of standard JS Array, adding convenience methods for manipulation. Add and remove changes to the Collection trigger a Collection event. Note that this does not cover changes to the objects within the Collection; they trigger events on the appropriate object, not on the Collection as a whole.

Fires

CollectionEvent

Api

Type Parameters

  • T

Hierarchy (view full)

Constructors

  • Type Parameters

    • T

    Parameters

    • Optional array: T[]

      Array.

    • Optional options: Options

      Collection options.

    Returns Collection<T>

Properties

disposed: boolean

The object has already been disposed.

on: CollectionOnSignature<T, EventsKey>
once: CollectionOnSignature<T, EventsKey>
un: CollectionOnSignature<T, void>

Methods

  • Parameters

    • key: string

      Key name.

    • listener: Listener

      Listener.

    Returns void

  • Parameters

    • type: string

      Type.

    • listener: Listener

      Listener.

    Returns void

  • Protected

    Apply any properties from another object without triggering events.

    Parameters

    • source: Object

      The source object.

    Returns void

  • Increases the revision counter and dispatches a 'change' event.

    Returns void

    Api

  • Remove all elements from the collection.

    Returns void

    Api

  • Dispatches an event and calls all listeners listening for events of this type. The event parameter can either be a string or an Object with a type property.

    Parameters

    • event: string | BaseEvent

      Event object.

    Returns undefined | boolean

    false if anyone called preventDefault on the event object or if any of the listeners returned false.

    Api

  • Clean up.

    Returns void

  • Protected

    Extension point for disposable objects.

    Returns void

  • Add elements to the collection. This pushes each item in the provided array to the end of the collection.

    Parameters

    • arr: T[]

      Array.

    Returns Collection<T>

    This collection.

    Api

  • Iterate over each element, calling the provided callback.

    Parameters

    • f: ((arg0, arg1, arg2) => any)

      The function to call for every element. This function takes 3 arguments (the element, the index and the array). The return value is ignored.

        • (arg0, arg1, arg2): any
        • Parameters

          • arg0: T
          • arg1: number
          • arg2: T[]

          Returns any

    Returns void

    Api

  • Gets a value.

    Parameters

    • key: string

      Key name.

    Returns any

    Value.

    Api

  • Get a reference to the underlying Array object. Warning: if the array is mutated, no events will be dispatched by the collection, and the collection's "length" property won't be in sync with the actual length of the array.

    Returns T[]

    Array.

    Api

  • Get a list of object property names.

    Returns string[]

    List of property names.

    Api

  • Get the length of this collection.

    Returns number

    The length of the array.

    Observable

    Api

  • Get the listeners for a specified event type. Listeners are returned in the order that they will be called in.

    Parameters

    • type: string

      Type.

    Returns undefined | Listener[]

    Listeners.

  • Get an object of all property names and values.

    Returns {
        [x: string]: any;
    }

    Object.

    • [x: string]: any

    Api

  • Get an object of all property names and values.

    Returns null | {
        [x: string]: any;
    }

    Object.

  • Get the version number for this object. Each time the object is modified, its version number will be incremented.

    Returns number

    Revision.

    Api

  • Parameters

    • Optional type: string

      Type. If not provided, true will be returned if this event target has any listeners.

    Returns boolean

    Has listeners.

  • Returns boolean

    The object has properties.

  • Insert an element at the provided index.

    Parameters

    • index: number

      Index.

    • elem: T

      Element.

    Returns void

    Api

  • Get the element at the provided index.

    Parameters

    • index: number

      Index.

    Returns T

    Element.

    Api

  • Parameters

    • key: string

      Key name.

    • oldValue: any

      Old value.

    Returns void

  • Protected

    Parameters

    • type: string | string[]

      Type.

    • listener: ((arg0) => unknown)

      Listener.

        • (arg0): unknown
        • Parameters

          • arg0: Event | BaseEvent

          Returns unknown

    Returns EventsKey | EventsKey[]

    Event key.

  • Protected

    Parameters

    • type: string | string[]

      Type.

    • listener: ((arg0) => unknown)

      Listener.

        • (arg0): unknown
        • Parameters

          • arg0: Event | BaseEvent

          Returns unknown

    Returns EventsKey | EventsKey[]

    Event key.

  • Remove the last element of the collection and return it. Return undefined if the collection is empty.

    Returns undefined | T

    Element.

    Api

  • Insert the provided element at the end of the collection.

    Parameters

    • elem: T

      Element.

    Returns number

    New length of the collection.

    Api

  • Remove the first occurrence of an element from the collection.

    Parameters

    • elem: T

      Element.

    Returns undefined | T

    The removed element or undefined if none found.

    Api

  • Remove the element at the provided index and return it. Return undefined if the collection does not contain this index.

    Parameters

    • index: number

      Index.

    Returns undefined | T

    Value.

    Api

  • Parameters

    • key: string

      Key name.

    • listener: Listener

      Listener.

    Returns void

  • Parameters

    • type: string

      Type.

    • listener: Listener

      Listener.

    Returns void

  • Sets a value.

    Parameters

    • key: string

      Key name.

    • value: any

      Value.

    • Optional silent: boolean

      Update without triggering an event.

    Returns void

    Api

  • Set the element at the provided index.

    Parameters

    • index: number

      Index.

    • elem: T

      Element.

    Returns void

    Api

  • Sets a collection of key-value pairs. Note that this changes any existing properties and adds new ones (it does not remove any existing properties).

    Parameters

    • values: {
          [x: string]: any;
      }

      Values.

      • [x: string]: any
    • Optional silent: boolean

      Update without triggering an event.

    Returns void

    Api

  • Protected

    Unlisten for a certain type of event.

    Parameters

    • type: string | string[]

      Type.

    • listener: ((arg0) => unknown)

      Listener.

        • (arg0): unknown
        • Parameters

          • arg0: Event | BaseEvent

          Returns unknown

    Returns void

  • Unsets a property.

    Parameters

    • key: string

      Key name.

    • Optional silent: boolean

      Unset without triggering an event.

    Returns void

    Api