ts-lib-extended
Version:
Additional types and tools for typescript
38 lines (37 loc) • 849 B
JavaScript
/**
* Provides basic stuff for disposable instances
*
* @export
* @abstract
* @class DisposableBase
* @since 1.0.0
*/
export class DisposableBase {
constructor() {
this._isDisposed = false;
}
get isDisposed() {
return this._isDisposed;
}
/**
* Dispose the instance (cleanup internals). The instance should and can no longer be used afterwards
*
* @return {*} {void}
* @memberof DisposableBase
* @since 1.0.0
*/
dispose() {
if (this.isDisposed) {
return;
}
this.disposingInstance();
this._isDisposed = true;
this.disposedInstance();
}
validateDisposed(value_) {
if (this.isDisposed || value_ === undefined) {
throw new Error('Instance is disposed!');
}
return value_;
}
}