##// END OF EJS Templates
`Subscribable` is made compatible with rxjs, added map, filter and scan...
`Subscribable` is made compatible with rxjs, added map, filter and scan methods to observables. `watch` can accept either stateful object and a property name to observe or the subscribable value. added ref attribute to the markup elements and widgets. `bind`, `tooggleClass` and `attach` methods can be passed to `ref` attribute in the markup to interact with elemnts and widgets.

File last commit:

r102:c65ea2350b1a v1.3
r102:c65ea2350b1a v1.3
Show More
Scope.ts
42 lines | 1.2 KiB | video/mp2t | TypeScriptLexer
import { IDestroyable, IRemovable } from "@implab/core-amd/interfaces";
import { isDestroyable, isRemovable } from "@implab/core-amd/safe";
import { isUnsubsribable, Unsubscribable } from "../observable";
export interface IScope {
own(target: (() => void) | IDestroyable | IRemovable | Unsubscribable): void;
}
export class Scope implements IDestroyable, IScope {
private readonly _cleanup: (() => void)[] = [];
static readonly dummy: IScope = { own() { } };
own(target: (() => void) | IDestroyable | IRemovable | Unsubscribable) {
if (target instanceof Function) {
this._cleanup.push(target);
} else if (isDestroyable(target)) {
this._cleanup.push(() => target.destroy());
} else if (isRemovable(target)) {
this._cleanup.push(() => target.remove());
} else if (isUnsubsribable(target)) {
this._cleanup.push(() => target.unsubscribe());
}
}
clean() {
const guard = (cb: () => void) => {
try {
cb();
} catch {
// guard
}
}
this._cleanup.forEach(guard);
this._cleanup.length = 0;
}
destroy() {
this.clean();
}
}