refactor: delegate signal effects to DisposableBag

Introduce `addEffect` to `DisposableBag` to encapsulate Preact
signal effect creation and disposal. Update `ReactiveScene` to use
this method, simplifying effect management and ensuring proper
cleanup.
This commit is contained in:
2026-04-20 18:18:26 +08:00
parent 45844ea800
commit 7039938a72
2 changed files with 12 additions and 2 deletions
@@ -1,3 +1,5 @@
import { effect } from "@preact/signals-core";
export interface IDisposable {
dispose(): void;
}
@@ -8,6 +10,10 @@ export class DisposableBag implements IDisposable {
private _disposables = new Set<DisposableItem>();
private _isDisposed = false;
constructor(go?: Phaser.GameObjects.GameObject) {
if (go) go.on("shutdown", () => this.dispose());
}
get isDisposed(): boolean {
return this._isDisposed;
}
@@ -20,6 +26,10 @@ export class DisposableBag implements IDisposable {
this._disposables.add(item);
}
addEffect(fn: () => void) {
this.add(effect(fn));
}
dispose(): void {
if (this._isDisposed) return;