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

ActionService

Action Service is what we call to dispatch actions and do whatever logic is needed prior to the dispatch. This reduces the number of actions we need to create, makes the code easier to read, centralizes the access to the store, and keeps logic out of the reducer and effects without scattering the logic throughout the application.

Constructor

constructor for the ActionService

Presentation
constructor(
	feature: string, 
	entity: string
): ActionService;
Parameters
NameTypeDescription
feature
string

the name of the feature this class is for

entity
string

the name of the entity this class is for

Properties

NameTypeDescription
entities
Observable<Dictionary<SmartNgRXRowBase>>
entityAdapter
EntityAdapter<SmartNgRXRowBase>

entityAdapter is needed for delete so it is public

Methods

add()

adds a row to the store

Presentation
add(row: SmartNgRXRowBase, parentId: string, parentService: ActionService): void;
Parameters
NameTypeDescription
row
SmartNgRXRowBase

the row to add

parentId
string

the id of the parent row

parentService
ActionService

the service for the parent row

Returns
void

delete()

Deletes the row represented by the Id from the store

Presentation
delete(id: string): void;
Parameters
NameTypeDescription
id
string

the id of the row to delete

Returns
void

forceDirty()

this forces the row to be marked as dirty regardless of any other conditions. Primarily used for websockets

Presentation
forceDirty(ids: string[]): void;
Parameters
NameTypeDescription
ids
string[]

the ids to mark as dirty

Returns
void

garbageCollect()

Rows that can be removed are unregisterd from the garbage collection and then removed from the store if they are not being edited.

Presentation
garbageCollect(ids: string[]): void;
Parameters
NameTypeDescription
ids
string[]

the ids to remove

Returns
void

init()

Tries to initialize the ActionService.

Presentation
init(): boolean;
Returns
boolean -

true if successful, false if not

loadByIds()

Calls the loadByIds action to load the rows into the store.

Presentation
loadByIds(ids: string[]): void;
Parameters
NameTypeDescription
ids
string[]

the ids to load

Returns
void

loadByIdsPreload()

adds dummy rows to the store for ones we are retrieving

Presentation
loadByIdsPreload(ids: string[]): void;
Parameters
NameTypeDescription
ids
string[]

the ids we are retrieving

Returns
void

loadByIdsSuccess()

puts the rows in the store

Presentation
loadByIdsSuccess(rows: SmartNgRXRowBase[]): void;
Parameters
NameTypeDescription
rows
SmartNgRXRowBase[]

the rows to put in the store

Returns
void

loadByIndexes()

que up loading the ids for the indexes

Presentation
loadByIndexes(parentId: string, childField: string, indexes: number[]): void;
Parameters
NameTypeDescription
parentId
string

the id of the parent row

childField
string

the child field to load

indexes
number[]

the indexes to load

Returns
void

loadByIndexesSuccess()

This updates the childField with the ids provided so we can use them in the VirtualArray. Make sure when you call this you are calling the service for the parent entity and not the child entity.

Presentation
loadByIndexesSuccess(parentId: string, childField: string, array: PartialArrayDefinition): void;
Parameters
NameTypeDescription
parentId
string

the id of the parent row so we can update the proper childField

childField
string

the child field to update

array
PartialArrayDefinition

specifiers that define the new partial array

Returns
void

markDirty()

marks the rows as dirty and takes into account settings indicating if this should cause a refresh or not

Presentation
markDirty(ids: string[]): void;
Parameters
NameTypeDescription
ids
string[]

the ids to mark as dirty

Returns
void

markNotDirty()

marks the rows represented by the ids as not dirty

Presentation
markNotDirty(ids: string[]): void;
Parameters
NameTypeDescription
ids
string[]

the ids to mark as not dirty

Returns
void

remove()

removes the rows represented by ids from the store unconditionally

Presentation
remove(ids: string[]): void;
Parameters
NameTypeDescription
ids
string[]

the ids of the rows to remove from the store

Returns
void

removeFromParents()

removes the id from the child arrays of the parent rows

Presentation
removeFromParents(id: string): ParentInfo[];
Parameters
NameTypeDescription
id
string

the id to remove

Returns
ParentInfo[] -

the parent info for each parent

replaceIdInParents()

replaces the id in the parent rows with the new id this is used when we commit a new row to the server

Presentation
replaceIdInParents(id: string, newId: string): void;
Parameters
NameTypeDescription
id
string

the id to replace

newId
string

the new id to replace the old id with

Returns
void

update()

updates the row in the store

Presentation
update(oldRow: SmartNgRXRowBase, newRow: SmartNgRXRowBase): void;
Parameters
NameTypeDescription
oldRow
SmartNgRXRowBase

the row before the changes

newRow
SmartNgRXRowBase

the row after the changes

Returns
void

updateMany()

updates many rows in the store

Presentation
updateMany(changes: UpdateStr<SmartNgRXRowBase>[]): void;
Parameters
NameTypeDescription
changes
UpdateStr<SmartNgRXRowBase>[]

the changes to make

Returns
void