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

ArrayProxy

Generic types:P C
Implements:SmartArray<P, C>ArrayLike<C>Iterable<C>

This is an internal class used by createSmartSelector to wrap the field that represents the child array with a class that manages all the magic of loading the data from the server as it is accessed.

Note: The constructor of this class returns a Proxy to intercept property accesses. This is an intentional and necessary design choice to achieve the desired behavior of dynamically loading data.

See Also

Constructor

The constructor for the ArrayProxy class.

Presentation
constructor(
	private childArray: string[] | ArrayProxy<P, C>, 
	private child: EntityState<C>, 
	private childDefinition: ChildDefinition<P, C>
): ArrayProxy<P, C>;
Parameters
NameTypeDescription
childArray
string[] | ArrayProxy<P, C>

The ArrayProxy or string[] of ids to wrap

child
EntityState<C>

The child EntityState we use to find the item in the store

childDefinition
ChildDefinition<P, C>

The ChildDefinition that allows us

Properties

NameTypeDescription
[isProxy]
boolean
childActionService
ActionService
entityAdapter
EntityAdapter<SmartNgRXRowBase>
length
implements ArrayLike
number
parentEntityAdapter
EntityAdapter<SmartNgRXRowBase>
rawArray
string[]

Methods

[Symbol.iterator]()

implements Iterable

Implements iterator so we can use methods that depend on iterable.

Presentation
[Symbol.iterator](): Iterator<C & RowProxyDelete, any, undefined>;
Returns
Iterator<C & RowProxyDelete, any, undefined> -

The next item in the iteration.

addToStore()

implements SmartArray

This method allows us to add an item to the array. Make sure it contains and ID field and any other defaults you might need

Presentation
addToStore(newRow: C, thisRow: P): void;
Parameters
NameTypeDescription
newRow
C

the item to add to the array

thisRow
P

the parent entity (this row) that contains the array

Returns
void

getAtIndex()

Allows us to go after the data in the store based on the index of the array.

Presentation
getAtIndex(index: number): C & RowProxyDelete;
Parameters
NameTypeDescription
index
number

the index into the rawArray that has the ID we will

Returns
C & RowProxyDelete -

the item from the store or the default row if it is not in the store yet.

getIdAtIndex()

implements SmartArray

returns the id at the given index, if the array is a virtual array, the id is returned without fetching from the server.

Presentation
getIdAtIndex(index: number): string | undefined;
Parameters
NameTypeDescription
index
number

the index to get the id at

Returns
string | undefined -

the id at the given index

getServices()

grabs common actions and store used by other methods

Presentation
getServices(): { service: ActionService; parentService: ActionService; };
Returns
{ service: ActionService; parentService: ActionService; } -

the ActionService for the child and the parent

init()

This initialized the class once it has been created. We do this so that we can test the class without having to worry about executable code in the constructor.

Presentation
init(): void;
Returns
void

removeFromStore()

implements SmartArray

This removes a row from the store that was previously added, but not saved to the server yet.

Presentation
removeFromStore(row: C, parent: P): void;
Parameters
NameTypeDescription
row
C

the row to remove from the array

parent
P

the parent entity that contains the array

Returns
void

toJSON()

This primarily exist for testing so you can stringify the array and then parse it so that you get an array you can compare against instead of an object of type ArrayProxy that you can't do much with.

Presentation
toJSON(): (C & RowProxyDelete)[];
Returns
(C & RowProxyDelete)[] -

what this would return if it were a real array. Mostly for unit testing.