Class Collection<T>

A generic array based collection. Implements the Symbol.iterator (e.g. [...collection])

Type Parameters

  • T

Hierarchy (view full)

Accessors

  • get uniqueKey(): undefined | keyof T
  • The key by which to check uniqueness against. undefined if no uniqueness constraint is set.

    Returns undefined | keyof T

Constructors

  • Type Parameters

    • T

    Parameters

    • OptionaluniqueKey: false | keyof T

      a key to maintain uniquely within the collection. passing false disables uniqueness.

    Returns Collection<T>

Methods

  • Protected

    internal remove function, to remove an item from the collection, does not raise an event.

    Parameters

    • item: T

    Returns number

    returns the index of the removed item or -1 if the item has not been found.

  • Adds an item to the collection.

    Parameters

    • item: T

      the item to be inserted

    Returns null | number

    the index at which the item was inserted

  • Returns an item identified by the unique constraint key. Returns null, if there is no uniqueness constraint.

    Parameters

    • value: unknown

      the value to test against. does a shallow comparison, if the passed a non-atomic value

    Returns undefined | T

  • Returns true, if the key exists. Returns undefined, if there is no uniqueness constraint.

    Parameters

    • value: unknown

    Returns undefined | boolean

  • Creates a Collection from an iterable, such as an Array.

    Type Parameters

    • F

    Parameters

    • iterable: Iterable<F, any, any>
    • OptionaluniqueKey: false | keyof F

      a key to maintain uniquely within the collection. passing false disables uniqueness.

    Returns Collection<F>

Properties

_array: T[]
added: VcsEvent<T>

Event raised if an item is added. Is passed the added item.

removed: VcsEvent<T>

Event raised if an item is removed. Is passed the removed item.