refactor: persistent hydration state
This commit is contained in:
parent
ed5d70bfec
commit
e8fb18c05e
|
@ -119,6 +119,7 @@ export class Entity extends decorate(Resource) {
|
|||
constructor(json, jsonext) {
|
||||
super();
|
||||
this._hooks = {};
|
||||
this._hydrationPromise = undefined;
|
||||
this._json = Entity.jsonWithDefaults(json);
|
||||
this._traits = {};
|
||||
this._traitsFlat = [];
|
||||
|
@ -230,11 +231,14 @@ export class Entity extends decorate(Resource) {
|
|||
}
|
||||
|
||||
hydrate() {
|
||||
const promises = [];
|
||||
for (let i = 0; i < this._traitsFlat.length; i++) {
|
||||
promises.push(this._traitsFlat[i].hydrate());
|
||||
if (!this._hydrationPromise) {
|
||||
const promises = [];
|
||||
for (let i = 0; i < this._traitsFlat.length; i++) {
|
||||
promises.push(this._traitsFlat[i].hydrate());
|
||||
}
|
||||
this._hydrationPromise = Promise.all(promises);
|
||||
}
|
||||
return Promise.all(promises);
|
||||
return this._hydrationPromise;
|
||||
}
|
||||
|
||||
invokeHook(hook, ...args) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user