fix: properly handle steps in entity list
This commit is contained in:
parent
de57404d59
commit
ee99aaa283
|
@ -59,24 +59,29 @@ export class EntityList extends decorate(class {}) {
|
|||
|
||||
patchStateStep(uuid, step) {
|
||||
const entity = this._entities[uuid];
|
||||
if ('remove' === step.op && '/' === step.path) {
|
||||
// Maybe already destroyed on the client?
|
||||
if (entity && entity.is('existent')) {
|
||||
entity.destroy();
|
||||
if ('/' === step.path) {
|
||||
switch (step.op) {
|
||||
case 'add':
|
||||
// New entity. Create with patch as traits.
|
||||
const newEntity = (new Entity()).fromJSON({
|
||||
traits: step.value,
|
||||
});
|
||||
newEntity.instanceUuid = uuid;
|
||||
this.addEntity(newEntity);
|
||||
break;
|
||||
case 'remove':
|
||||
// Maybe already destroyed on the client?
|
||||
if (entity && entity.is('existent')) {
|
||||
entity.destroy();
|
||||
}
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (entity) {
|
||||
if ('replace' === step.op && entity) {
|
||||
// Exists; patch.
|
||||
entity.patchState([step]);
|
||||
}
|
||||
else {
|
||||
// New entity. Create with patch as traits.
|
||||
const newEntity = (new Entity()).fromJSON({
|
||||
traits: step.value,
|
||||
});
|
||||
newEntity.instanceUuid = uuid;
|
||||
this.addEntity(newEntity);
|
||||
}
|
||||
}
|
||||
|
||||
get quadTree() {
|
||||
|
|
Loading…
Reference in New Issue
Block a user