refactor: immutable optimizations
This commit is contained in:
parent
bf18ae019a
commit
400b2ebb7d
|
@ -97,10 +97,12 @@ export class EntityList extends decorate(Synchronized) {
|
|||
const entity = this._entities[uuid];
|
||||
entity.tick(elapsed);
|
||||
}
|
||||
for (const uuid in this._entities) {
|
||||
const entity = this._entities[uuid];
|
||||
this.state = this.state.set(uuid, entity.state);
|
||||
}
|
||||
this.state = this.state.withMutations((state) => {
|
||||
for (const uuid in this._entities) {
|
||||
const entity = this._entities[uuid];
|
||||
state.set(uuid, entity.state);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
visibleEntities(query) {
|
||||
|
|
|
@ -56,16 +56,22 @@ export class Synchronized extends decorate(class {}) {
|
|||
}
|
||||
|
||||
tick(elapsed) {
|
||||
for (const key of this.synchronizedChildren()) {
|
||||
const children = this.synchronizedChildren();
|
||||
for (const key of children) {
|
||||
if (this[key] instanceof Synchronized) {
|
||||
this[key].tick(elapsed);
|
||||
this.state = this.state.set(key, this[key].state);
|
||||
}
|
||||
else {
|
||||
this.state = this.state.set(key, this[key]);
|
||||
}
|
||||
}
|
||||
|
||||
this.state = this.state.withMutations((state) => {
|
||||
for (const key of children) {
|
||||
if (this[key] instanceof Synchronized) {
|
||||
state.set(key, this[key].state);
|
||||
}
|
||||
else {
|
||||
state.set(key, this[key]);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -36,8 +36,13 @@ export class Synchronizer {
|
|||
for (const key in this._statefuls) {
|
||||
const stateful = this._statefuls[key];
|
||||
stateful.tick(elapsed);
|
||||
this._state = this._state.set(key, stateful.state);
|
||||
}
|
||||
this._state = this._state.withMutations((state) => {
|
||||
for (const key in this._statefuls) {
|
||||
const stateful = this._statefuls[key];
|
||||
state.set(key, stateful.state);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -115,8 +115,13 @@ export class Layers extends decorate(Synchronized) {
|
|||
for (const index in this.layers) {
|
||||
const layer = this.layers[index];
|
||||
layer.tick(elapsed);
|
||||
this.state = this.state.set(index, layer.state);
|
||||
}
|
||||
this.state = this.state.withMutations((state) => {
|
||||
for (const index in this.layers) {
|
||||
const layer = this.layers[index];
|
||||
state.set(index, layer.state);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user