fix: entity.toNetwork

This commit is contained in:
cha0s 2019-10-07 05:13:49 -05:00
parent b3baaedde9
commit f308ebb469
2 changed files with 16 additions and 7 deletions

View File

@ -274,11 +274,11 @@ export class Entity extends decorate(Resource) {
return pristine;
}
mergeDiff() {
mergeDiff(json) {
if (!this.uri) {
return this.toJSON();
return json;
}
return mergeDiff(this._json, this.toJSON());
return mergeDiff(this._json, json);
}
packets(informed) {
@ -391,8 +391,16 @@ export class Entity extends decorate(Resource) {
}
}
toNetwork() {
return this.mergeDiff();
toNetwork(informed) {
const json = {
...super.toJSON(),
instanceUuid: this.instanceUuid,
traits: {},
};
for (const type in this._traits) {
json.traits[type] = this._traits[type].toNetwork(informed);
}
return this.mergeDiff(json);
}
toJSON() {

View File

@ -210,14 +210,15 @@ export class EntityList extends decorate(class {}) {
// Mark as notified.
this._informedEntities.set(informed, visibleEntities);
return visibleEntities.map((entity) => {
return entity.mergeDiff();
return entity.toNetwork(informed);
});
}
toJSON() {
const json = [];
for (let i = 0; i < this._flatEntities.length; i++) {
json.push(this._flatEntities[i].mergeDiff());
const entity = this._flatEntities[i];
json.push(entity.mergeDiff(entity.toJSON()));
}
return json;
}