Skip to content

@serenity-is/corelib / Lookup

Class: Lookup<TItem>

Defined in: src/base/lookup.ts:19

Concrete implementation of the Lookup interface for client-side use. Maintains items and a itemById index synchronized via Lookup.update.

Example

const lookup = new Lookup<{ id: number; name: string }>({ idField: "id", textField: "name" }, items);
lookup.itemById["5"] // item with id 5

Type Parameters

TItem

TItem

Type of the lookup items.

Constructors

Constructor

new Lookup<TItem>(options, items?): Lookup<TItem>

Defined in: src/base/lookup.ts:59

Creates a new lookup instance.

Parameters

options

LookupOptions<TItem>

Field mapping for id/parent/text. Pass null/undefined for an empty configuration (fields remain undefined).

items?

TItem[]

Optional initial item array. If provided, update is called immediately to populate items and itemById.

Returns

Lookup<TItem>

Properties

idField

idField: string

Defined in: src/base/lookup.ts:25

Name of the ID field (copied from LookupOptions.idField).


itemById

itemById: object

Defined in: src/base/lookup.ts:23

Dictionary mapping stringified LookupOptions.idField values to their corresponding items.

Index Signature

[key: string]: TItem


items

items: TItem[]

Defined in: src/base/lookup.ts:21

Flat array of all lookup items.


parentIdField

parentIdField: string

Defined in: src/base/lookup.ts:27

Name of the parent-ID field for hierarchical lookups (copied from LookupOptions.parentIdField).


textField

textField: string

Defined in: src/base/lookup.ts:29

Name of the display-text field (copied from LookupOptions.textField).

Methods

update()?

optional update(value): void

Defined in: src/base/lookup.ts:76

Replaces the lookup contents and rebuilds the itemById index.

Parameters

value

TItem[]

New item array. null/undefined clears the lookup. Primitive values (e.g. string numbers from a distinct query) are auto-wrapped as { [idField]: value, [textField]: value }.

Returns

void

Remarks

Re-initializes both Lookup.items and Lookup.itemById. The method is declared optional (update?) on the interface for compatibility with plain-object lookups, but is always present on this class.