refactor: persistent hydration state

This commit is contained in:
cha0s 2019-05-22 06:24:29 -05:00
parent ed5d70bfec
commit e8fb18c05e

View File

@ -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() {
if (!this._hydrationPromise) {
const promises = [];
for (let i = 0; i < this._traitsFlat.length; i++) {
promises.push(this._traitsFlat[i].hydrate());
}
return Promise.all(promises);
this._hydrationPromise = Promise.all(promises);
}
return this._hydrationPromise;
}
invokeHook(hook, ...args) {