##// END OF EJS Templates
Implemented subscription SubscriptionImpl, fixed subscription resource management
Implemented subscription SubscriptionImpl, fixed subscription resource management

File last commit:

r131:c7d9ad82b374 v1.8.1 default
r158:078eca3dc271 v1.10.3 default
Show More
Scope.ts
54 lines | 1.4 KiB | video/mp2t | TypeScriptLexer
cin
Added Renderer, WatchRendition
r94 import { IDestroyable, IRemovable } from "@implab/core-amd/interfaces";
import { isDestroyable, isRemovable } from "@implab/core-amd/safe";
cin
added whenRendered() method to wait for pending oprations to complete
r118 import { isUnsubscribable, Unsubscribable } from "../observable";
cin
Added Renderer, WatchRendition
r94
export interface IScope {
cin
`Subscribable` is made compatible with rxjs, added map, filter and scan...
r102 own(target: (() => void) | IDestroyable | IRemovable | Unsubscribable): void;
cin
Added Renderer, WatchRendition
r94 }
cin
Corrected Scope.own() to cleanup the supplied object immediately when the scope is disposed already
r131 const guard = (cb: () => void) => {
try {
cb();
} catch {
// guard
}
};
cin
Added Renderer, WatchRendition
r94 export class Scope implements IDestroyable, IScope {
cin
Corrected Scope.own() to cleanup the supplied object immediately when the scope is disposed already
r131 private readonly _pending: (() => void)[] = [];
private _disposed = false;
cin
Added Renderer, WatchRendition
r94
static readonly dummy: IScope = { own() { } };
cin
`Subscribable` is made compatible with rxjs, added map, filter and scan...
r102 own(target: (() => void) | IDestroyable | IRemovable | Unsubscribable) {
cin
Added Renderer, WatchRendition
r94 if (target instanceof Function) {
cin
Corrected Scope.own() to cleanup the supplied object immediately when the scope is disposed already
r131 this._own(target);
cin
Added Renderer, WatchRendition
r94 } else if (isDestroyable(target)) {
cin
Corrected Scope.own() to cleanup the supplied object immediately when the scope is disposed already
r131 this._own(() => target.destroy());
cin
Added Renderer, WatchRendition
r94 } else if (isRemovable(target)) {
cin
Corrected Scope.own() to cleanup the supplied object immediately when the scope is disposed already
r131 this._own(() => target.remove());
cin
added whenRendered() method to wait for pending oprations to complete
r118 } else if (isUnsubscribable(target)) {
cin
Corrected Scope.own() to cleanup the supplied object immediately when the scope is disposed already
r131 this._own(() => target.unsubscribe());
cin
Added Renderer, WatchRendition
r94 }
}
cin
Corrected Scope.own() to cleanup the supplied object immediately when the scope is disposed already
r131 private _own(target: () => void) {
if (this._disposed)
guard(target);
else
this._pending.push(target);
}
cin
Added Renderer, WatchRendition
r94 clean() {
cin
Corrected Scope.own() to cleanup the supplied object immediately when the scope is disposed already
r131 this._pending.forEach(guard);
this._pending.length = 0;
cin
Added Renderer, WatchRendition
r94 }
destroy() {
cin
Corrected Scope.own() to cleanup the supplied object immediately when the scope is disposed already
r131 if (!this._disposed) {
this._disposed = true;
this.clean();
}
cin
Added Renderer, WatchRendition
r94 }
}