@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()
new MemoryStore(modelOrOptions:
| Model
| MemoryStoreOptions, data: any[]): MemoryStoreDefined 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.
data
any[] = []
Optional. The initial data records to load into the store. Ignored when the first argument is a MemoryStoreOptions bag.
Returns
Overrides
Properties
model
readonly model: Model;Defined in: src/typescript/lib/data/MemoryStore.ts:23
Overrides
proxy
readonly proxy: MemoryProxy;Defined in: src/typescript/lib/data/MemoryStore.ts:24
Overrides
Methods
add()
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
An array of the newly created ModelRecord instances.
Inherited from
clearFilter()
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
clearSort()
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
filter()
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
filterBy()
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
The filter descriptor to apply.
Returns
Promise<void>
Inherited from
find()
find(property: string, value: any): undefined | ModelRecordDefined 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
findAll()
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
An array of all matching ModelRecords; empty if none match.
Inherited from
getActiveSorter()
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
getActiveSorters()
getActiveSorters(): SortDescriptor[]Defined in: src/typescript/lib/data/AbstractStore.ts:709
Returns a copy of all active sort descriptors in priority order.
Returns
A shallow-copy array of the active sort descriptors; empty when no sort is active.
Inherited from
AbstractStore.getActiveSorters
getAll()
getAll(): ModelRecord[]Defined in: src/typescript/lib/data/AbstractStore.ts:386
Returns a copy of all records, bypassing any active filters or sorting.
Returns
A shallow-copy array of every record in the store.
Inherited from
getAt()
getAt(index: number): undefined | ModelRecordDefined 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
getById()
getById(id: any): undefined | ModelRecordDefined 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
getCount()
getCount(): numberDefined 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
getPage()
getPage(): numberDefined 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
getPageSize()
getPageSize(): undefined | numberDefined 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
getRecords()
getRecords(): ModelRecord[]Defined in: src/typescript/lib/data/AbstractStore.ts:377
Returns a copy of the currently filtered and sorted records.
Returns
A shallow-copy array of the records in the active view.
Inherited from
getTotalCount()
getTotalCount(): undefined | numberDefined 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
getTotalPages()
getTotalPages(): undefined | numberDefined 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
goToPage()
goToPage(n: number): thisDefined 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
hasPendingChanges()
hasPendingChanges(): booleanDefined 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()
isLoading(): booleanDefined 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
load()
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
loadData()
loadData(data: any[]): voidDefined 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
nextPage()
nextPage(): voidDefined 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
notifyRecordChanged()
notifyRecordChanged(_record: ModelRecord): voidDefined 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
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()
off(event: StoreEvent, listener: StoreListener): voidDefined in: src/typescript/lib/data/AbstractStore.ts:821
Removes a previously registered store event listener.
Parameters
event
The name of the store event the listener was registered for.
listener
The callback function to remove.
Returns
void
Inherited from
on()
on(event: StoreEvent, listener: StoreListener): voidDefined in: src/typescript/lib/data/AbstractStore.ts:804
Subscribes a listener to a store event.
Parameters
event
The name of the store event to listen for.
listener
The callback function to invoke when the event fires.
Returns
void
Inherited from
prevPage()
prevPage(): voidDefined 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
reject()
reject(): voidDefined 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
remove()
remove(record: ModelRecord): thisDefined in: src/typescript/lib/data/AbstractStore.ts:488
Removes a record from the store, queuing it for deletion on the next sync.
Parameters
record
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
removeAll()
removeAll(): thisDefined 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
setPageSize()
setPageSize(n: number): thisDefined 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
sort()
Call Signature
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
Call Signature
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
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
sync()
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.