diff --git a/packages/entity/src/resources/entity.js b/packages/entity/src/resources/entity.js index 2cd7a0c..53c42ed 100644 --- a/packages/entity/src/resources/entity.js +++ b/packages/entity/src/resources/entity.js @@ -30,8 +30,6 @@ export default (flecks) => { $$markedAsDirty = true; - $$originalJson; - $$tickingPromisesTickers = []; $$traits = {}; @@ -257,9 +255,6 @@ export default (flecks) => { async load(json = {}) { await super.load(json); const {instanceUuid, traits = {}} = json; - if (!this.$$originalJson) { - this.$$originalJson = json; - } this.instanceUuid = instanceUuid || this.numericUid; await this.addTraits(traits); } @@ -380,7 +375,7 @@ export default (flecks) => { const [type, trait] = traits[i]; pristine.traits = pristine.traits || {}; pristine.traits[type] = trait.constructor.withDefaults( - this.$$originalJson ? this.$$originalJson.traits[type] : {}, + this.$$extendedJson ? this.$$extendedJson.traits[type] : {}, ); json.traits = json.traits || {}; json.traits[type] = trait.toJSON(); @@ -413,7 +408,7 @@ export default (flecks) => { for (let i = 0; i < traits.length; i++) { const [type, trait] = traits[i]; pristine.traits[type] = trait.constructor.withDefaults( - this.$$originalJson ? this.$$originalJson.traits[type] : {}, + this.$$extendedJson ? this.$$extendedJson.traits[type] : {}, ); json.traits[type] = trait.toNetwork(informed); } diff --git a/packages/resource/src/json-resource.js b/packages/resource/src/json-resource.js index 76efb90..d3ab5b0 100644 --- a/packages/resource/src/json-resource.js +++ b/packages/resource/src/json-resource.js @@ -5,9 +5,7 @@ import Resource from './resource'; export default class JsonResource extends Resource { - async extendAndLoad(json) { - return this.load(await this.constructor.extendJson(json)); - } + $$extendedJson; static async extendJson(json) { return this.mergeJson( @@ -22,14 +20,19 @@ export default class JsonResource extends Resource { static async load(json = {}) { const resource = new this(); - await resource.load(await this.extendJson( - 'string' === typeof json.extends - ? { - ...json, - uri: json.extends, - } - : json, - )); + if ('string' === typeof json.extends) { + const {extends: xtends, ...rest} = json; + const extendedJson = await this.extendJson({extends: xtends}); + resource.$$extendedJson = extendedJson; + await resource.load(await this.mergeJson({ + extends: extendedJson, + ...rest, + uri: xtends, + })); + } + else { + await resource.load(json); + } return resource; }