Skip to content

Commit

Permalink
fix: fix unintentional children mutation (#586)
Browse files Browse the repository at this point in the history
  • Loading branch information
marianyp authored Jan 15, 2025
1 parent 3ad6bbe commit 7f34947
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions src/game/make.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,22 +140,16 @@ export function make<T>(comps: CompList<T> = []): GameObj<T> {
},

remove(obj: GameObj): void {
const idx = this.children.indexOf(obj);

if (idx !== -1) {
obj.parent = null;
this.children.splice(idx, 1);
obj.parent = null;

const trigger = (o: GameObj) => {
o.trigger("destroy");
_k.game.events.trigger("destroy", o);
o.children.forEach((child) => trigger(child));
};
const trigger = (o: GameObj) => {
o.trigger("destroy");
_k.game.events.trigger("destroy", o);
o.children.forEach((child) => trigger(child));
};

trigger(obj);
}
trigger(obj);
},

// TODO: recursive
removeAll(this: GameObj, tag?: Tag) {
if (tag) {
Expand Down

0 comments on commit 7f34947

Please sign in to comment.