mirror of
https://github.com/unanmed/HumanBreak.git
synced 2026-11-25 02:05:59 +08:00
资源分离
This commit is contained in:
1 parent
39c655d355
commit
1bdfb9be7d
14 files changed
+245
-18
No files matched your search
@@ -0,0 +1,36 @@
|
||||
import { EmitableEvent, EventEmitter } from './eventEmitter';
|
||||
|
||||
interface DisposableEvent<T> extends EmitableEvent {
|
||||
active: (value: T) => void;
|
||||
dispose: (value: T) => void;
|
||||
}
|
||||
|
||||
export class Disposable<T> extends EventEmitter<DisposableEvent<T>> {
|
||||
protected _data: T;
|
||||
set data(value: T | null) {
|
||||
if (value !== null) this._data = value;
|
||||
}
|
||||
get data(): T | null {
|
||||
if (!this.activated) {
|
||||
return null;
|
||||
}
|
||||
return this._data;
|
||||
}
|
||||
|
||||
protected activated: boolean = false;
|
||||
|
||||
constructor(data: T) {
|
||||
super();
|
||||
this._data = data;
|
||||
}
|
||||
|
||||
active() {
|
||||
this.activated = true;
|
||||
this.emit('active', this._data);
|
||||
}
|
||||
|
||||
dispose() {
|
||||
this.activated = false;
|
||||
this.emit('dispose', this._data);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user