Skip to content

@serenity-is/corelib / Lookup

Class: Lookup<TItem>

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

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:77

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

cssClassField

cssClassField: string

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

Name of the CSS class field (copied from LookupOptions.cssClassField).


iconField

iconField: string

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

Name of the icon field (copied from LookupOptions.iconField).


idField

idField: string

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

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


itemById

itemById: object

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

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

Index Signature

[key: string]: TItem


items

items: TItem[]

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

Flat array of all lookup items.


parentIdField

parentIdField: string

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

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


textField

textField: string

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

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


textKeyField

textKeyField: string

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

Name of the text key field (copied from LookupOptions.textKeyField).

Methods

update()?

optional update(value): void

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

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.