Skip to content

@jimka/typescript-ui / data / MemoryStore

Class: MemoryStore

Defined in: src/typescript/lib/data/MemoryStore.ts:21

A store backed entirely by in-memory data. Useful for testing or for static datasets that do not require server persistence.

Extends

Constructors

new MemoryStore()

ts
new MemoryStore(modelOrOptions: 
  | Model
  | MemoryStoreOptions, data: any[]): MemoryStore

Defined in: src/typescript/lib/data/MemoryStore.ts:32

Constructs a MemoryStore with the given model and an optional initial data array.

Parameters

modelOrOptions

The Model that defines the record schema, or a MemoryStoreOptions bag.

Model | MemoryStoreOptions

data

any[] = []

Optional. The initial data records to load into the store. Ignored when the first argument is a MemoryStoreOptions bag.

Returns

MemoryStore

Overrides

AbstractStore.constructor

Properties

model

ts
readonly model: Model;

Defined in: src/typescript/lib/data/MemoryStore.ts:23

Overrides

AbstractStore.model


proxy

ts
readonly proxy: MemoryProxy;

Defined in: src/typescript/lib/data/MemoryStore.ts:24

Overrides

AbstractStore.proxy

Methods

add()

ts
add(data: any): ModelRecord[]

Defined in: src/typescript/lib/data/AbstractStore.ts:458

Adds one or more records (marked as new), updates the view, and fires 'add'/'datachanged'.

Parameters

data

any

A single plain object or an array of plain objects to add.

Returns

ModelRecord[]

An array of the newly created ModelRecord instances.

Inherited from

AbstractStore.add


clearFilter()

ts
clearFilter(): Promise<void>

Defined in: src/typescript/lib/data/AbstractStore.ts:779

Removes all active filters and fires 'datachanged'.

Returns

Promise<void>

Remarks

When server-side pagination is enabled, this method also resets the current page to 1 and triggers a fire-and-forget reload so the proxy is queried without filter context.

Inherited from

AbstractStore.clearFilter


clearSort()

ts
clearSort(): Promise<void>

Defined in: src/typescript/lib/data/AbstractStore.ts:731

Removes any active sort and restores insertion order, firing 'sortchanged' and 'datachanged'.

Returns

Promise<void>

A promise that resolves once the local view has been rebuilt.

Inherited from

AbstractStore.clearSort


filter()

ts
filter(property: string, value: any): Promise<void>

Defined in: src/typescript/lib/data/AbstractStore.ts:748

Adds an equality filter on a property and fires 'datachanged'.

Parameters

property

string

The field name to filter on.

value

any

The value a record's field must equal to pass the filter.

Returns

Promise<void>

Inherited from

AbstractStore.filter


filterBy()

ts
filterBy(descriptor: FilterDescriptor): Promise<void>

Defined in: src/typescript/lib/data/AbstractStore.ts:763

Adds a filter described by a serializable FilterDescriptor. Descriptors cross the worker boundary cleanly (unlike arbitrary predicate functions), so the same call works for in-process and worker-offloaded evaluation.

Parameters

descriptor

FilterDescriptor

The filter descriptor to apply.

Returns

Promise<void>

Inherited from

AbstractStore.filterBy


find()

ts
find(property: string, value: any): undefined | ModelRecord

Defined in: src/typescript/lib/data/AbstractStore.ts:433

Returns the first record in the filtered view where property equals value.

Parameters

property

string

The field name to match against.

value

any

The value to compare using strict equality.

Returns

undefined | ModelRecord

The first matching ModelRecord, or undefined if none is found.

Inherited from

AbstractStore.find


findAll()

ts
findAll(property: string, value: any): ModelRecord[]

Defined in: src/typescript/lib/data/AbstractStore.ts:445

Returns all records in the filtered view where property equals value.

Parameters

property

string

The field name to match against.

value

any

The value to compare using strict equality.

Returns

ModelRecord[]

An array of all matching ModelRecords; empty if none match.

Inherited from

AbstractStore.findAll


getActiveSorter()

ts
getActiveSorter(): 
  | null
  | {
  direction: "desc" | "asc";
  property: string;
}

Defined in: src/typescript/lib/data/AbstractStore.ts:720

Returns a copy of the primary active sorter config, or null if no sort is active.

Returns

| null | { direction: "desc" | "asc"; property: string; }

The first active sorter mapped to the legacy { property, direction } shape, or null.

Deprecated

Use getActiveSorters instead.

Inherited from

AbstractStore.getActiveSorter


getActiveSorters()

ts
getActiveSorters(): SortDescriptor[]

Defined in: src/typescript/lib/data/AbstractStore.ts:709

Returns a copy of all active sort descriptors in priority order.

Returns

SortDescriptor[]

A shallow-copy array of the active sort descriptors; empty when no sort is active.

Inherited from

AbstractStore.getActiveSorters


getAll()

ts
getAll(): ModelRecord[]

Defined in: src/typescript/lib/data/AbstractStore.ts:386

Returns a copy of all records, bypassing any active filters or sorting.

Returns

ModelRecord[]

A shallow-copy array of every record in the store.

Inherited from

AbstractStore.getAll


getAt()

ts
getAt(index: number): undefined | ModelRecord

Defined in: src/typescript/lib/data/AbstractStore.ts:406

Returns the record at the given index in the filtered view, or undefined.

Parameters

index

number

The zero-based position in the filtered and sorted view.

Returns

undefined | ModelRecord

The ModelRecord at that position, or undefined if the index is out of range.

Inherited from

AbstractStore.getAt


getById()

ts
getById(id: any): undefined | ModelRecord

Defined in: src/typescript/lib/data/AbstractStore.ts:417

Finds a record by its primary-key value, searching all records (ignoring filters).

Parameters

id

any

The primary key value to search for.

Returns

undefined | ModelRecord

The matching ModelRecord, or undefined if not found or no primary key is defined.

Inherited from

AbstractStore.getById


getCount()

ts
getCount(): number

Defined in: src/typescript/lib/data/AbstractStore.ts:395

Returns the number of records in the current filtered view.

Returns

number

The count of visible records after filters are applied.

Inherited from

AbstractStore.getCount


getPage()

ts
getPage(): number

Defined in: src/typescript/lib/data/AbstractStore.ts:245

Returns the current 1-based page number.

Returns

number

The current page (defaults to 1 even when pagination is disabled).

Inherited from

AbstractStore.getPage


getPageSize()

ts
getPageSize(): undefined | number

Defined in: src/typescript/lib/data/AbstractStore.ts:236

Returns the configured page size, or undefined if pagination is disabled.

Returns

undefined | number

The page size set via setPageSize, or undefined.

Inherited from

AbstractStore.getPageSize


getRecords()

ts
getRecords(): ModelRecord[]

Defined in: src/typescript/lib/data/AbstractStore.ts:377

Returns a copy of the currently filtered and sorted records.

Returns

ModelRecord[]

A shallow-copy array of the records in the active view.

Inherited from

AbstractStore.getRecords


getTotalCount()

ts
getTotalCount(): undefined | number

Defined in: src/typescript/lib/data/AbstractStore.ts:255

Returns the total record count reported by the most recent paginated load.

Returns

undefined | number

The total count from the proxy, or undefined when no paginated load has occurred or the proxy did not report one.

Inherited from

AbstractStore.getTotalCount


getTotalPages()

ts
getTotalPages(): undefined | number

Defined in: src/typescript/lib/data/AbstractStore.ts:265

Returns the total number of pages, derived from the page size and total count.

Returns

undefined | number

The number of pages, or undefined when either piece of information is missing.

Inherited from

AbstractStore.getTotalPages


goToPage()

ts
goToPage(n: number): this

Defined in: src/typescript/lib/data/AbstractStore.ts:334

Jumps to the given 1-based page and reloads.

Parameters

n

number

The target page number; clamped to [1, totalPages] when total is known.

Returns

this

Remarks

No-op when pagination is disabled. Blocked when the store has pending changes — emits 'pagechangeblocked' instead.

Inherited from

AbstractStore.goToPage


hasPendingChanges()

ts
hasPendingChanges(): boolean

Defined in: src/typescript/lib/data/AbstractStore.ts:554

Returns whether the store holds any unsynced state.

Returns

boolean

True if any record is dirty, any record is new, or there are queued removals waiting to be synced.

Remarks

Used by the pagination guard to prevent navigation that would silently discard in-memory edits. Also useful for "unsaved changes" prompts.

Inherited from

AbstractStore.hasPendingChanges


isLoading()

ts
isLoading(): boolean

Defined in: src/typescript/lib/data/AbstractStore.ts:182

Returns whether the store is currently loading data.

Returns

boolean

True while load() is in-flight.

Inherited from

AbstractStore.isLoading


load()

ts
load(): Promise<void>

Defined in: src/typescript/lib/data/AbstractStore.ts:154

Fetches data through the proxy, replaces all records, and fires the 'load' event.

Returns

Promise<void>

A promise that resolves when the data has been loaded and the view rebuilt.

Remarks

Throws an Error if no proxy is configured. Any existing records (including pending removals) are discarded when new data is ingested.

Inherited from

AbstractStore.load


loadData()

ts
loadData(data: any[]): void

Defined in: src/typescript/lib/data/AbstractStore.ts:205

Loads raw data directly without going through the proxy, then fires 'load'.

Parameters

data

any[]

An array of plain objects to convert into ModelRecords.

Returns

void

Inherited from

AbstractStore.loadData


nextPage()

ts
nextPage(): void

Defined in: src/typescript/lib/data/AbstractStore.ts:283

Advances to the next page and reloads, unless already on the last page.

Returns

void

Remarks

No-op when pagination is disabled or the current page equals the total page count. When the store has pending unsynced changes, the navigation is blocked and 'pagechangeblocked' is emitted instead, so the user can sync or reject before leaving the page. Otherwise fires 'pagechanged' and triggers a fire-and-forget reload.

Inherited from

AbstractStore.nextPage


notifyRecordChanged()

ts
notifyRecordChanged(_record: ModelRecord): void

Defined in: src/typescript/lib/data/AbstractStore.ts:540

Signals that a record's fields were mutated outside the store's own mutation methods (e.g. an in-cell edit in a Table).

Parameters

_record

ModelRecord

The record that was edited. Forwarded by callers so future listeners can identify it; currently unused by the store itself.

Returns

void

Remarks

Fires 'datachanged' so listeners (toolbars, pagination bars, etc.) re-evaluate state such as hasPendingChanges. The record's dirty flag is already set by record.set(); this method just notifies.

Inherited from

AbstractStore.notifyRecordChanged


off()

ts
off(event: StoreEvent, listener: StoreListener): void

Defined in: src/typescript/lib/data/AbstractStore.ts:821

Removes a previously registered store event listener.

Parameters

event

StoreEvent

The name of the store event the listener was registered for.

listener

StoreListener

The callback function to remove.

Returns

void

Inherited from

AbstractStore.off


on()

ts
on(event: StoreEvent, listener: StoreListener): void

Defined in: src/typescript/lib/data/AbstractStore.ts:804

Subscribes a listener to a store event.

Parameters

event

StoreEvent

The name of the store event to listen for.

listener

StoreListener

The callback function to invoke when the event fires.

Returns

void

Inherited from

AbstractStore.on


prevPage()

ts
prevPage(): void

Defined in: src/typescript/lib/data/AbstractStore.ts:310

Returns to the previous page and reloads, unless already on page 1.

Returns

void

Remarks

Blocked when the store has pending changes — emits 'pagechangeblocked' instead of firing 'pagechanged'.

Inherited from

AbstractStore.prevPage


reject()

ts
reject(): void

Defined in: src/typescript/lib/data/AbstractStore.ts:579

Discards all unsynced changes — reverts dirty records, drops new ones, and restores pending removals — then fires 'datachanged'.

Returns

void

Remarks

Pending removals are pushed back into allRecords (in their original order is not preserved; they are appended) so the user can recover from an accidental removal. Dirty records are restored to their last committed values. New records are dropped outright since they were never persisted.

Inherited from

AbstractStore.reject


remove()

ts
remove(record: ModelRecord): this

Defined in: src/typescript/lib/data/AbstractStore.ts:488

Removes a record from the store, queuing it for deletion on the next sync.

Parameters

record

ModelRecord

The ModelRecord to remove.

Returns

this

Remarks

New records (never synced) are discarded immediately without being queued. Records that have been persisted are added to pendingRemoved and sent to the proxy during the next call to sync().

Inherited from

AbstractStore.remove


removeAll()

ts
removeAll(): this

Defined in: src/typescript/lib/data/AbstractStore.ts:516

Removes all records, queuing existing (non-new) ones for deletion on the next sync.

Returns

this

Remarks

Only persisted records are queued for removal; records that are still marked as new are simply discarded.

Inherited from

AbstractStore.removeAll


setPageSize()

ts
setPageSize(n: number): this

Defined in: src/typescript/lib/data/AbstractStore.ts:223

Enables server-side pagination at the given page size and resets to page 1.

Parameters

n

number

The number of records to request per page. Must be a positive integer.

Returns

this

Remarks

Calling this method opts the store into the paginated load() path, where ReadParams are forwarded to the proxy. Paginated mode also causes sort() and clearFilter() to reset to page 1 and re-fetch from the proxy. Fires 'pagechanged'.

Inherited from

AbstractStore.setPageSize


sort()

Call Signature

ts
sort(field: string, dir?: "desc" | "asc"): Promise<void>

Defined in: src/typescript/lib/data/AbstractStore.ts:668

Sorts the view by a single property in the given direction.

Parameters
field

string

The field name to sort by.

dir?

Optional. The sort direction; defaults to 'asc'.

"desc" | "asc"

Returns

Promise<void>

A promise that resolves once the local view has been rebuilt.

Remarks

When server-side pagination is enabled, this method also resets the current page to 1 and triggers a fire-and-forget reload so the proxy receives the new ordering. Fires 'sortchanged' and 'datachanged'.

Inherited from

AbstractStore.sort

Call Signature

ts
sort(descriptors: SortDescriptor[]): Promise<void>

Defined in: src/typescript/lib/data/AbstractStore.ts:681

Applies a multi-column sort. Pass an empty array to clear all sorters.

Parameters
descriptors

SortDescriptor[]

The ordered list of sort descriptors. Earlier descriptors take priority.

Returns

Promise<void>

A promise that resolves once the local view has been rebuilt.

Remarks

Mirrors the single-column overload's pagination side effects when server-side pagination is enabled.

Inherited from

AbstractStore.sort


sync()

ts
sync(): Promise<void>

Defined in: src/typescript/lib/data/AbstractStore.ts:616

Persists new, dirty, and removed records via the proxy, then fires 'sync'/'datachanged'.

Returns

Promise<void>

A promise that resolves when all pending operations have completed.

Remarks

Sync is a no-op when no proxy is configured. Operations are performed in order: creates first, then updates, then deletes. Each record is committed after its operation succeeds so it no longer appears in subsequent sync cycles.

Inherited from

AbstractStore.sync