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.

CollectionEvent

Type Parameters

  • T

Hierarchy (view full)

Constructors

  • Type Parameters

    • T

    Parameters

    • Optionalarray: T[]

      Array.

    • Optionaloptions: 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

  • Remove all elements from the collection.

    Returns void

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

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

  • Iterate over each element, calling the provided callback.

    Parameters

    • f: ((arg0: T, arg1: number, arg2: T[]) => 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

  • Gets a value.

    Parameters

    • key: string

      Key name.

    Returns any

    Value.

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

  • Get a list of object property names.

    Returns string[]

    List of property names.

  • Get the length of this collection.

    Returns number

    The length of the array.

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

  • Parameters

    • Optionaltype: 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

  • Get the element at the provided index.

    Parameters

    • index: number

      Index.

    Returns T

    Element.

  • Parameters

    • key: string

      Key name.

    • oldValue: any

      Old value.

    Returns void

  • Protected

    Parameters

    • type: string | string[]

      Type.

    • listener: ((arg0: Event | BaseEvent) => unknown)

      Listener.

        • (arg0): unknown
        • Parameters

          • arg0: Event | BaseEvent

          Returns unknown

    Returns EventsKey | EventsKey[]

    Event key.

  • Protected

    Parameters

    • type: string | string[]

      Type.

    • listener: ((arg0: Event | BaseEvent) => 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.

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

    Parameters

    • elem: T

      Element.

    Returns number

    New length of the collection.

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

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

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

    • Optionalsilent: boolean

      Update without triggering an event.

    Returns void

  • Set the element at the provided index.

    Parameters

    • index: number

      Index.

    • elem: T

      Element.

    Returns void

  • 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
    • Optionalsilent: boolean

      Update without triggering an event.

    Returns void

  • Protected

    Unlisten for a certain type of event.

    Parameters

    • type: string | string[]

      Type.

    • listener: ((arg0: Event | BaseEvent) => unknown)

      Listener.

        • (arg0): unknown
        • Parameters

          • arg0: Event | BaseEvent

          Returns unknown

    Returns void

  • Unsets a property.

    Parameters

    • key: string

      Key name.

    • Optionalsilent: boolean

      Unset without triggering an event.

    Returns void