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:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user