Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ControllerCache<T>

Cache holder for controllers.

Type parameters

Hierarchy

Index

Constructors

constructor

  • new ControllerCache(entries?: Iterable<keyof [T["id"], T]> | null, limit?: undefined | number): ControllerCache

Properties

Readonly limit

limit: number | null | undefined

The maximum number of items allowed in this Collection

Readonly size

size: number

Accessors

first

  • get first(): T | undefined

firstKey

  • get firstKey(): T["id"] | undefined

last

  • get last(): T | undefined

lastKey

  • get lastKey(): T["id"] | undefined

toArray

  • get toArray(): T[]

toArrayEntries

  • get toArrayEntries(): [T["id"], T][]

toArrayKeys

  • get toArrayKeys(): T["id"][]

Methods

add

  • add(item: T): T

addMany

  • addMany(items: T[]): void

clear

  • clear(): void
  • Returns void

delete

  • delete(key: T["id"]): boolean
  • Parameters

    • key: T["id"]

    Returns boolean

every

  • every(cb: (value: T, key: T["id"], collection: this) => boolean): boolean

filter

  • filter<T>(cb: (value: T, key?: K, collection?: this) => boolean): Collection<T["id"], T>
  • Creates a new Collection with all elements that pass the test implemented by the provided callback. Identical to {@link Array.prototype.filter}

    Type parameters

    • T: T

    Parameters

    • cb: (value: T, key?: K, collection?: this) => boolean

      Callback function. Return true to keep the element, false otherwise

        • (value: T, key?: K, collection?: this): boolean
        • Parameters

          • value: T
          • Optional key: K
          • Optional collection: this

          Returns boolean

    Returns Collection<T["id"], T>

find

  • find(cb: (value: T, key: T["id"], collection: this) => boolean): T | undefined

forEach

  • forEach(callbackfn: (value: T, key: T["id"], map: Map<T["id"], T>) => void, thisArg?: any): void
  • Parameters

    • callbackfn: (value: T, key: T["id"], map: Map<T["id"], T>) => void
        • (value: T, key: T["id"], map: Map<T["id"], T>): void
        • Parameters

          • value: T
          • key: T["id"]
          • map: Map<T["id"], T>

          Returns void

    • Optional thisArg: any

    Returns void

get

  • get(key: T["id"]): T | undefined
  • Parameters

    • key: T["id"]

    Returns T | undefined

getMany

  • getMany(keys: T["id"][]): (undefined | V)[]
  • Returns the matching values for the given keys inside the Collection.

    Parameters

    • keys: T["id"][]

      Array of all keys to look for

    Returns (undefined | V)[]

getOrSet

  • getOrSet(key: T["id"], value: T): T
  • Returns the item if exists or creates a new one and caches it.

    Parameters

    • key: T["id"]

      The key of the item

    • value: T

      The value of the item

    Returns T

has

  • has(key: T["id"]): boolean
  • Parameters

    • key: T["id"]

    Returns boolean

map

  • map<R>(cb: (value: T, key: T["id"], collection: this) => R): Collection<T["id"], R>
  • Create a new Collection populated with the results of calling a provided callback on every element in the calling Collection. Identical to {@link Array.prototype.map}

    template

    V

    Type parameters

    • R

      is the type of the values the new Collection will contain

    Parameters

    • cb: (value: T, key: T["id"], collection: this) => R

      Callback function. The returned value is added to the new Collection

        • (value: T, key: T["id"], collection: this): R
        • Parameters

          • value: T
          • key: T["id"]
          • collection: this

          Returns R

    Returns Collection<T["id"], R>

merge

  • merge(...collections: (Collection<K, V> | [K, V][])[]): void
  • ֛Merges collection(s) on top of this one. Replaces existing keys by newer Collections

    Parameters

    • Rest ...collections: (Collection<K, V> | [K, V][])[]

      The collection(s) to be merged on top of this one

    Returns void

pop

  • pop(): [T["id"], T] | undefined

set

  • set(key: T["id"], value: T, force?: undefined | false | true): this
  • Checks if the Collection has reached its limit and sets the item using {@link Map.prototype.set}

    Parameters

    • key: T["id"]

      The key to set

    • value: T

      The value to set

    • Optional force: undefined | false | true

      Whether to add the item to the Collection if its limit was reached

    Returns this

shift

  • shift(): [T["id"], T] | undefined

some

  • some(cb: (value: T, key: T["id"], collection: this) => boolean): boolean

Static isCollection

  • isCollection<K, V>(collection: unknown): collection is Collection<K, V>
  • Whether the given argument is a Collection

    Type parameters

    • K

    • V

    Parameters

    • collection: unknown

      Data to check if collection

    Returns collection is Collection<K, V>

Generated using TypeDoc