Skip to content

@jimka/typescript-ui / data / MemoryProxy

Class: MemoryProxy

Defined in: src/typescript/lib/data/proxy/MemoryProxy.ts:31

An in-memory proxy that stores data as a plain JavaScript array. All operations resolve synchronously via Promise.resolve.

Remarks

Because this proxy holds no external state, data is lost when the page is refreshed or the proxy instance is discarded. It is primarily intended for testing and for stores that manage transient, client-only data.

Extends

Constructors

new MemoryProxy()

ts
new MemoryProxy(options: MemoryProxyOptions): MemoryProxy

Defined in: src/typescript/lib/data/proxy/MemoryProxy.ts:40

Constructs a MemoryProxy, optionally pre-populated with an initial data array.

Parameters

options

MemoryProxyOptions = ...

Optional. Options object containing the initial data array.

Returns

MemoryProxy

Overrides

Proxy.constructor

Methods

create()

ts
create(record: ModelRecord): Promise<Record<string, any>>

Defined in: src/typescript/lib/data/proxy/MemoryProxy.ts:73

Appends a copy of the record's data to the in-memory array.

Parameters

record

ModelRecord

The new ModelRecord to store.

Returns

Promise<Record<string, any>>

A promise that resolves to the stored copy of the record's data.

Overrides

Proxy.create


destroy()

ts
destroy(record: ModelRecord): Promise<void>

Defined in: src/typescript/lib/data/proxy/MemoryProxy.ts:119

Removes the matching entry from the in-memory array by primary key.

Parameters

record

ModelRecord

The ModelRecord to remove.

Returns

Promise<void>

A promise that resolves when the removal is complete.

Remarks

If the model has no primary key or the record is not found, the array is left unchanged and the method still resolves successfully.

Overrides

Proxy.destroy


getLastTotalCount()

ts
getLastTotalCount(): undefined | number

Defined in: src/typescript/lib/data/proxy/Proxy.ts:84

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

Returns

undefined | number

The total count from the last paginated response, or undefined if the proxy does not support pagination or no paginated read has occurred.

Remarks

Default implementation returns undefined. Pagination-aware proxies (such as AjaxProxy) override this to return the total value parsed from the server envelope.

Inherited from

Proxy.getLastTotalCount


read()

ts
read(_params?: ReadParams): Promise<any[]>

Defined in: src/typescript/lib/data/proxy/MemoryProxy.ts:62

Returns a copy of the in-memory data array.

Parameters

_params?

ReadParams

Optional. Pagination parameters; ignored by this proxy.

Returns

Promise<any[]>

A promise that resolves to a shallow copy of the current data array.

Overrides

Proxy.read


setData()

ts
setData(data: any[]): void

Defined in: src/typescript/lib/data/proxy/MemoryProxy.ts:51

Replaces the in-memory data array used by this proxy.

Parameters

data

any[]

The new data array; a shallow copy is stored internally.

Returns

void


update()

ts
update(record: ModelRecord): Promise<Record<string, any>>

Defined in: src/typescript/lib/data/proxy/MemoryProxy.ts:92

Updates the matching entry in the in-memory array by primary key.

Parameters

record

ModelRecord

The dirty ModelRecord whose data should replace the existing entry.

Returns

Promise<Record<string, any>>

A promise that resolves to the updated copy of the record's data.

Remarks

If the model has no primary key or the record is not found in the array, the array is left unchanged and the method still resolves successfully.

Overrides

Proxy.update