fix: JSON extension tracking
This commit is contained in:
parent
d2e4b64d2c
commit
3bca7da3bf
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
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);
|
||||
}
|
||||
: json,
|
||||
));
|
||||
return resource;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user