Home
Using Smart NgRX
Demo Walkthrough
API
@smarttools/smart-ngrx / Class

RowProxy

Generic types:T
Implements:RowProxyDelete

RowProxy wraps the row so we can intercept changes to it and fire off the appropriate actions to update the store and the server.

Since proxying the row directly will cause the setter to throw an error when the NgRX rules are turned on that disallow mutating the row directly, we need to wrap the row in our own class that uses the Proxy class to handle the updates. By casting the RowProxy to type T (above) the rest of our code still believes it is working with the original row.

Constructor

This is the constructor for the RowProxy class.

Presentation
constructor(
	row: T, 
	private service: ActionService, 
	parentService: ActionService
): RowProxy<T>;
Parameters
NameTypeDescription
row
T

The row to create the custom proxy for

service
ActionService

The service that will handle updating the row

parentService
ActionService

The service that will handle updating the parent row

Properties

NameTypeDescription
changes
Record<string | symbol, unknown>
record
Record<string | symbol, unknown>

Methods

delete()

implements RowProxyDelete

Initiates delete of this object from the server which will also optimistically update the store

Presentation
delete(): void;
Returns
void

getRealRow()

This retrieves the backing row for this proxy

Presentation
getRealRow(): T;
Returns
T -

the backing row for this proxy

toJSON()

When we stringify this object, it needs to stringify the real row and any changes we've made to it.

Presentation
toJSON(): T & Record<string | symbol, unknown>;
Returns
T & Record<string | symbol, unknown> -

the real row with any changes we've made to it