forked from johnpapa/angular-ngrx-data
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entity-collection.ts
46 lines (42 loc) · 1.5 KB
/
entity-collection.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { EntityState } from '@ngrx/entity';
import { Dictionary } from '../utils/ngrx-entity-models';
/** Types of change in a ChangeState instance */
export enum ChangeType {
/** The entity has not changed from its last known server state. */
Unchanged = 0,
/** The entity was added to the collection */
Added,
/** The entity is scheduled for delete and was removed from the collection */
Deleted,
/** The entity in the collection was updated */
Updated
}
/**
* Change state for an entity with unsaved changes;
* an entry in an EntityCollection.changeState map
*/
export interface ChangeState<T> {
changeType: ChangeType;
originalValue?: T | undefined;
}
/**
* Map of entity primary keys to entity ChangeStates.
* Each entry represents an entity with unsaved changes.
*/
export type ChangeStateMap<T> = Dictionary<ChangeState<T>>;
/**
* Data and information about a collection of entities of a single type.
* EntityCollections are maintained in the EntityCache within the ngrx store.
*/
export interface EntityCollection<T = any> extends EntityState<T> {
/** Name of the entity type for this collection */
entityName: string;
/** A map of ChangeStates, keyed by id, for entities with unsaved changes */
changeState: ChangeStateMap<T>;
/** The user's current collection filter pattern */
filter: string;
/** true if collection was ever filled by QueryAll; forced false if cleared */
loaded: boolean;
/** true when a query or save operation is in progress */
loading: boolean;
}