Class AncestryCollection<T, CT>

Type Parameters

  • T extends Model

  • CT extends string = "children"

Hierarchy

Constructors

Properties

childrenRelation: CT

The name of the attribute that includes the related models.

length: number = 0

The length of the collection.

depthName: string = 'depth'

The name of the key that will be set when arranging the items in a tree structure.

Methods

  • See

    Array.prototype.every

    Type Parameters

    Parameters

    • predicate: ((value, index, array) => value is S)
        • (value, index, array): value is S
        • Parameters

          • value: Ancestralised<T, CT>
          • index: number
          • array: Ancestralised<T, CT>[]

          Returns value is S

    • Optional thisArg: any

    Returns this is S[]

  • Parameters

    • predicate: ((value, index, array) => unknown)
        • (value, index, array): unknown
        • Parameters

          • value: Ancestralised<T, CT>
          • index: number
          • array: Ancestralised<T, CT>[]

          Returns unknown

    • Optional thisArg: any

    Returns boolean

  • See

    Array.prototype.find

    Parameters

    • predicate: ((value, index, obj) => unknown)
        • (value, index, obj): unknown
        • Parameters

          • value: Ancestralised<T, CT>
          • index: number
          • obj: Ancestralised<T, CT>[]

          Returns unknown

    • Optional thisArg: any

    Returns undefined | Ancestralised<T, CT>

  • See

    Array.prototype.findIndex

    Parameters

    • predicate: ((value, index, obj) => unknown)
        • (value, index, obj): unknown
        • Parameters

          • value: Ancestralised<T, CT>
          • index: number
          • obj: Ancestralised<T, CT>[]

          Returns unknown

    • Optional thisArg: any

    Returns number

  • Return the first element in the collection, if callback given the first element that passes the truth test. Otherwise, undefined.

    Parameters

    • Optional callback: ((item, index) => boolean)
        • (item, index): boolean
        • Parameters

          • item: Ancestralised<T, CT>
          • index: number

          Returns boolean

    Returns undefined | Ancestralised<T, CT>

  • See

    Array.prototype.flatMap

    Type Parameters

    • U

    • This = undefined

    Parameters

    • callback: ((this, value, index, array) => U | readonly U[])
        • (this, value, index, array): U | readonly U[]
        • Parameters

          • this: This
          • value: Ancestralised<T, CT>
          • index: number
          • array: Ancestralised<T, CT>[]

          Returns U | readonly U[]

    • Optional thisArg: This

    Returns Collection<U>

  • See

    Array.prototype.join

    Parameters

    • Optional key: string | ((item) => any)
    • separator: undefined | string | ((item) => any) = key

    Returns string

  • Return the last element in the collection, if callback given the last element that passes the truth test. Otherwise, undefined.

    Parameters

    • Optional callback: ((item, index) => boolean)
        • (item, index): boolean
        • Parameters

          • item: Ancestralised<T, CT>
          • index: number

          Returns boolean

    Returns undefined | Ancestralised<T, CT>

  • See

    Array.prototype.reduce

    Parameters

    • callback: ((previousValue, currentValue, currentIndex, array) => Ancestralised<T, CT>)
        • (previousValue, currentValue, currentIndex, array): Ancestralised<T, CT>
        • Parameters

          • previousValue: Ancestralised<T, CT>
          • currentValue: Ancestralised<T, CT>
          • currentIndex: number
          • array: Ancestralised<T, CT>[]

          Returns Ancestralised<T, CT>

    • Optional initialValue: Ancestralised<T, CT>

    Returns Ancestralised<T, CT>

  • See

    Array.prototype.reduceRight

    Parameters

    • callback: ((previousValue, currentValue, currentIndex, array) => Ancestralised<T, CT>)
        • (previousValue, currentValue, currentIndex, array): Ancestralised<T, CT>
        • Parameters

          • previousValue: Ancestralised<T, CT>
          • currentValue: Ancestralised<T, CT>
          • currentIndex: number
          • array: Ancestralised<T, CT>[]

          Returns Ancestralised<T, CT>

    • Optional initialValue: Ancestralised<T, CT>

    Returns Ancestralised<T, CT>

  • See

    Array.prototype.some

    Parameters

    • predicate: ((value, index, array) => unknown)
        • (value, index, array): unknown
        • Parameters

          • value: Ancestralised<T, CT>
          • index: number
          • array: Ancestralised<T, CT>[]

          Returns unknown

    • Optional thisArg: any

    Returns boolean

  • Arrange the items in an ancestry tree format.

    Type Parameters

    • ST extends Model<ST>

    • CT extends string = "children"

    Parameters

    • models: ModelCollection<ST> | ST[]

      The ModelCollection to sort.

    • parentKey: string = 'parentId'

      The key that identifies the parent's id.

    • childrenRelation: CT = ...

      The key that will include descendants.

    Returns AncestryCollection<ST, CT>

Generated using TypeDoc