Skip to content

@maxhealth.tech/prefab / rx / Collection

Class: Collection<T>

Defined in: rx/collection.ts:87

A named keyed array. Serializes rows into state and provides typed lookup helpers that compile to pipe expressions.

Type Parameters

Type ParameterDefault type
T extends Record<string, unknown>Record<string, unknown>

Constructors

Constructor

ts
new Collection<T>(
   stateKey, 
   rows, 
keyField): Collection<T>;

Defined in: rx/collection.ts:92

Parameters

ParameterType
stateKeystring
rowsT[]
keyFieldstring

Returns

Collection<T>

Properties

stateKey

ts
readonly stateKey: string;

Defined in: rx/collection.ts:88


keyField

ts
readonly keyField: string;

Defined in: rx/collection.ts:89


rows

ts
readonly rows: T[];

Defined in: rx/collection.ts:90

Accessors

length

Get Signature

ts
get length(): number;

Defined in: rx/collection.ts:113

Number of rows.

Returns

number

Methods

firstKey()

ts
firstKey(): string | null;

Defined in: rx/collection.ts:99

Key of the first row, or null if empty.

Returns

string | null


lastKey()

ts
lastKey(): string | null;

Defined in: rx/collection.ts:106

Key of the last row, or null if empty.

Returns

string | null


by()

ts
by<K>(key): Ref<T>;

Defined in: rx/collection.ts:121

Create a Ref that lazily resolves a row by signal key. Compiles to: {{ stateKey | find:'keyField',signal.key }}

Type Parameters

Type Parameter
K extends SignalValue

Parameters

ParameterType
keySignal<K>

Returns

Ref<T>


toRx()

ts
toRx(): Rx;

Defined in: rx/collection.ts:126

Rx expression referencing the full array: {{ stateKey }}

Returns

Rx


toString()

ts
toString(): string;

Defined in: rx/collection.ts:130

Returns

string


toJSON()

ts
toJSON(): string;

Defined in: rx/collection.ts:134

Returns

string


toState()

ts
toState(): Record<string, T[]>;

Defined in: rx/collection.ts:139

State entry for PrefabApp: { stateKey: rows }

Returns

Record<string, T[]>

Released under the MIT License.