refactor: misc
This commit is contained in:
@@ -1,8 +1,3 @@
|
||||
import { h, Fragment } from 'preact';
|
||||
import { effect } from '@preact/signals-core';
|
||||
|
||||
type DisposeFn = () => void;
|
||||
|
||||
export interface GameUIOptions {
|
||||
container: HTMLElement;
|
||||
root: any;
|
||||
@@ -11,7 +6,6 @@ export interface GameUIOptions {
|
||||
export class GameUI {
|
||||
private container: HTMLElement;
|
||||
private root: any;
|
||||
private effects: DisposeFn[] = [];
|
||||
|
||||
constructor(options: GameUIOptions) {
|
||||
this.container = options.container;
|
||||
@@ -24,19 +18,9 @@ export class GameUI {
|
||||
});
|
||||
}
|
||||
|
||||
watch(fn: () => void): DisposeFn {
|
||||
const e = effect(fn);
|
||||
this.effects.push(e);
|
||||
return e;
|
||||
}
|
||||
|
||||
unmount(): void {
|
||||
import('preact').then(({ render }) => {
|
||||
render(null, this.container);
|
||||
});
|
||||
for (const e of this.effects) {
|
||||
e();
|
||||
}
|
||||
this.effects = [];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user