EntityManager
EntityManager
holds the data state.
Constructor
constructor
constructor(options: Options): EntityManager
Parameters:
Name | Type | Required | Description |
---|---|---|---|
options | Options | object | Yes | The EntityManager options. Can be an Options instance or directly the parameter to pass on the Options constructor |
Methods
hasPendingChanges
hasPendingChanges(): boolean
There is pending changes when you use AbstractRepository#persist or AbstractRepository#remove without having flushed yet.
Returns:
Type: boolean
isFullyLoaded
isFullyLoaded(): boolean
It is fully loaded only if all repositories are loaded.
Returns:
Type: boolean
getRepository
getRepository(name: string): AbstractRepository|null
Parameters:
Name | Type | Required | Description |
---|---|---|---|
name | string | Yes | The repository name you want to retrieve |
Returns:
Type: AbstractRepository|null
getRepositoryNames
getRepositoryNames(): Array<string>
Returns:
Type: Array<string>
getRepositories
getRepositories(): Array<AbstractRepository>
Returns:
Type: Array<AbstractRepository>
load
async load(fallbackOnCache: boolean = true): Promise<void, Error>
Loads data from API
Parameters:
Name | Type | Required | Default | Description |
---|---|---|---|---|
fallbackOnCache | boolean | No | true | If request to API fail, then it will fallback to CacheManager if this parameter is true |
Returns:
Type: Promise<void, Error>
loadFromCache
async loadFromCache(allowOutdated: boolean = false): Promise<void, Error>
Loads data from cache
Parameters:
Name | Type | Required | Default | Description |
---|---|---|---|---|
allowOutdated | boolean | No | false | If the cache is not up-to-date, it will reject the loading. See Offline - Cache First |
Returns:
Type: Promise<void, Error>
flush
async flush(): Promise<void, Error>
Flush pending changes to API
Returns:
Type: Promise<void, Error>
pull
async pull(): Promise<void, Error>
Pull external changes, it will reload the EntityManager and publish events corresponding to modifications.
You must ensure the EntityManager has no pending changes before trying to synchronise.
Returns:
Type: Promise<void, Error>