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,4 +1,4 @@
import { effect, type ReadonlySignal } from "@preact/signals-core";
import { type ReadonlySignal } from "@preact/signals-core";
import { Scene } from "phaser";
import { DisposableBag, type IDisposable } from "../utils";
@@ -85,6 +85,6 @@ export abstract class ReactiveScene<TData = object>
/** 注册响应式监听(场景关闭时自动清理) */
public addEffect(fn: () => CleanupFn): void {
this.disposables.add(effect(fn));
this.disposables.addEffect(fn);
}
}