Skip to content

Commit

Permalink
fix(BatchedText): Fix removing text instances via .remove()
Browse files Browse the repository at this point in the history
  • Loading branch information
lojjic committed Nov 21, 2024
1 parent d2eab04 commit d99549f
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions packages/troika-three-text/src/BatchedText.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ export class BatchedText extends Text {
this._onMemberSynced = (e) => {
this._members.get(e.target).dirty = true;
};
this._onMemberRemoved = (e) => {
this.removeText(e.target);
};
}

/**
Expand All @@ -86,6 +83,20 @@ export class BatchedText extends Text {
return this;
}

/**
* @override
*/
remove (...objects) {
for (let i = 0; i < objects.length; i++) {
if (objects[i] instanceof Text) {
this.removeText(objects[i]);
} else {
super.remove(objects[i]);
}
}
return this;
}

/**
* @param {Text} text
*/
Expand All @@ -96,7 +107,6 @@ export class BatchedText extends Text {
glyphCount: -1,
dirty: true
});
text.addEventListener("removed", this._onMemberRemoved);
text.addEventListener("synccomplete", this._onMemberSynced);
}
}
Expand All @@ -105,7 +115,6 @@ export class BatchedText extends Text {
* @param {Text} text
*/
removeText (text) {
text.removeEventListener("removed", this._onMemberRemoved);
text.removeEventListener("synccomplete", this._onMemberSynced);
this._members.delete(text);
}
Expand Down

0 comments on commit d99549f

Please sign in to comment.