Options
All
  • Public
  • Public/Protected
  • All
Menu

A map which creates new items if they don't already exist. Useful for guaranteeing the existence of values without null checks all over the place

Type parameters

  • T

    The type of item being stored

  • A: unknown[]

    A tuple representing the arguments for .get(...)

Hierarchy

  • FactoryMap

Index

Constructors

Properties

Methods

Constructors

constructor

  • new FactoryMap<T, A>(createItem: (...args: A) => T): FactoryMap<T, A>
  • Type parameters

    • T

    • A: unknown[]

    Parameters

    • createItem: (...args: A) => T

      Used to create a new item if it doesn't exist in the map. Receives the arguments passed to .get(...)

        • (...args: A): T
        • Parameters

          • Rest ...args: A

          Returns T

    Returns FactoryMap<T, A>

Properties

Private Readonly items

items: Map<string, T> = ...

Methods

clear

  • clear(): void

get

  • get(...args: A): T
  • If an item was already created with the given arguments, return that item. Otherwise, create a new item, passing the arguments to the createItem function.

    Parameters

    • Rest ...args: A

    Returns T

values

  • values(): IterableIterator<T>
  • Gets all the values in the map. This is an iterator, so you need to convert it to an array to use array methods, e.g. [...map.values].map(...)

    Returns IterableIterator<T>

Generated using TypeDoc