fix: JSON extension tracking

This commit is contained in:
cha0s 2022-05-08 16:10:11 -05:00
parent d2e4b64d2c
commit 3bca7da3bf
2 changed files with 16 additions and 18 deletions

View File

@ -30,8 +30,6 @@ export default (flecks) => {
$$markedAsDirty = true; $$markedAsDirty = true;
$$originalJson;
$$tickingPromisesTickers = []; $$tickingPromisesTickers = [];
$$traits = {}; $$traits = {};
@ -257,9 +255,6 @@ export default (flecks) => {
async load(json = {}) { async load(json = {}) {
await super.load(json); await super.load(json);
const {instanceUuid, traits = {}} = json; const {instanceUuid, traits = {}} = json;
if (!this.$$originalJson) {
this.$$originalJson = json;
}
this.instanceUuid = instanceUuid || this.numericUid; this.instanceUuid = instanceUuid || this.numericUid;
await this.addTraits(traits); await this.addTraits(traits);
} }
@ -380,7 +375,7 @@ export default (flecks) => {
const [type, trait] = traits[i]; const [type, trait] = traits[i];
pristine.traits = pristine.traits || {}; pristine.traits = pristine.traits || {};
pristine.traits[type] = trait.constructor.withDefaults( pristine.traits[type] = trait.constructor.withDefaults(
this.$$originalJson ? this.$$originalJson.traits[type] : {}, this.$$extendedJson ? this.$$extendedJson.traits[type] : {},
); );
json.traits = json.traits || {}; json.traits = json.traits || {};
json.traits[type] = trait.toJSON(); json.traits[type] = trait.toJSON();
@ -413,7 +408,7 @@ export default (flecks) => {
for (let i = 0; i < traits.length; i++) { for (let i = 0; i < traits.length; i++) {
const [type, trait] = traits[i]; const [type, trait] = traits[i];
pristine.traits[type] = trait.constructor.withDefaults( pristine.traits[type] = trait.constructor.withDefaults(
this.$$originalJson ? this.$$originalJson.traits[type] : {}, this.$$extendedJson ? this.$$extendedJson.traits[type] : {},
); );
json.traits[type] = trait.toNetwork(informed); json.traits[type] = trait.toNetwork(informed);
} }

View File

@ -5,9 +5,7 @@ import Resource from './resource';
export default class JsonResource extends Resource { export default class JsonResource extends Resource {
async extendAndLoad(json) { $$extendedJson;
return this.load(await this.constructor.extendJson(json));
}
static async extendJson(json) { static async extendJson(json) {
return this.mergeJson( return this.mergeJson(
@ -22,14 +20,19 @@ export default class JsonResource extends Resource {
static async load(json = {}) { static async load(json = {}) {
const resource = new this(); const resource = new this();
await resource.load(await this.extendJson( if ('string' === typeof json.extends) {
'string' === typeof json.extends const {extends: xtends, ...rest} = json;
? { const extendedJson = await this.extendJson({extends: xtends});
...json, resource.$$extendedJson = extendedJson;
uri: json.extends, await resource.load(await this.mergeJson({
} extends: extendedJson,
: json, ...rest,
)); uri: xtends,
}));
}
else {
await resource.load(json);
}
return resource; return resource;
} }