##// END OF EJS Templates
refactoring, all common interfaces placed to core/interfaces.ts...
refactoring, all common interfaces placed to core/interfaces.ts added core/components/Observable.ts

File last commit:

r13:745612edbd74 propose cancellat...
r13:745612edbd74 propose cancellat...
Show More
ActivatableMixin.ts
86 lines | 2.5 KiB | video/mp2t | TypeScriptLexer
/ src / ts / components / ActivatableMixin.ts
cin
refactoring, all common interfaces placed to core/interfaces.ts...
r13 import { IActivationController, IActivatable, ICancellation } from '../interfaces';
cin
Async operation cancellation proposal...
r9 import { AsyncComponent } from './AsyncComponent';
cin
refactoring, all common interfaces placed to core/interfaces.ts...
r13 import { Cancellation } from '../Cancellation';
cin
added TraceSource tests
r11 import * as TraceSource from '../log/TraceSource';
cin
Async operation cancellation proposal...
r9
type Constructor<T = {}> = new (...args: any[]) => T;
cin
added TraceSource tests
r11 const log = TraceSource.get('@implab/core/components/ActivatableMixin');
cin
Async operation cancellation proposal...
r9 function ActivatableMixin<TBase extends Constructor<AsyncComponent>>(Base: TBase) {
return class extends Base implements IActivatable {
_controller: IActivationController;
_active: boolean;
isActive() {
return this._active;
}
getActivationController() {
return this._controller;
}
setActivationController(controller: IActivationController) {
this._controller = controller;
}
async onActivating(ct: ICancellation) {
if (this._controller)
await this._controller.activating(this, ct);
}
async onActivated(ct: ICancellation) {
if (this._controller)
await this._controller.activated(this, ct);
}
cin
refactoring, all common interfaces placed to core/interfaces.ts...
r13 activate(ct: ICancellation = Cancellation.none) {
return this.runOperation(this._activateAsync.bind(this), ct);
}
async _activateAsync(ct: ICancellation) {
cin
Async operation cancellation proposal...
r9 if (this.isActive())
return;
cin
refactoring, all common interfaces placed to core/interfaces.ts...
r13
await this.onActivating(ct);
this._active = true;
cin
Async operation cancellation proposal...
r9 try {
cin
refactoring, all common interfaces placed to core/interfaces.ts...
r13 await this.onActivated(ct);
cin
Async operation cancellation proposal...
r9 } catch (e) {
cin
refactoring, all common interfaces placed to core/interfaces.ts...
r13 log.error("Suppressed onActivated error: {0}", e);
cin
Async operation cancellation proposal...
r9 }
}
async onDeactivating(ct: ICancellation) {
if (this._controller)
await this._controller.deactivating(this, ct);
}
async onDeactivated(ct: ICancellation) {
if (this._controller)
await this._controller.deactivated(this, ct);
}
cin
refactoring, all common interfaces placed to core/interfaces.ts...
r13 deactivate(ct: ICancellation = Cancellation.none) {
return this.runOperation(this._deactivateAsync.bind(this), ct);
}
async _deactivateAsync(ct: ICancellation) {
cin
Async operation cancellation proposal...
r9 if (!this.isActive())
return;
cin
refactoring, all common interfaces placed to core/interfaces.ts...
r13 await this.onDeactivating(ct);
this._active = false;
cin
Async operation cancellation proposal...
r9 try {
cin
refactoring, all common interfaces placed to core/interfaces.ts...
r13 await this.onDeactivated(ct);
cin
Async operation cancellation proposal...
r9 } catch (e) {
cin
refactoring, all common interfaces placed to core/interfaces.ts...
r13 log.error("Suppressed onDeactivated error: {0}", e);
cin
Async operation cancellation proposal...
r9 }
}
}
}
namespace ActivatableMixin {
cin
removed obsolete code
r12 export const traceSource = log;
cin
Async operation cancellation proposal...
r9 }
export = ActivatableMixin;