##// END OF EJS Templates
Added tag v1.4.0 for changeset 1a8a956a013f
Added tag v1.4.0 for changeset 1a8a956a013f

File last commit:

r148:cd81c631015f v1.4.0-rc6 default
r157:f563f4b24ce3 default
Show More
Registry.ts
55 lines | 1.4 KiB | video/mp2t | TypeScriptLexer
cin
minor refactoring of TraceSource, code linting
r53 import { TraceSource } from "./TraceSource";
import { argumentNotNull } from "../safe";
cin
corrected code to support ts strict mode...
r115 import { IDestroyable, MapOf } from "../interfaces";
cin
minor refactoring of TraceSource, code linting
r53
export class Registry {
static readonly instance = new Registry();
cin
corrected code to support ts strict mode...
r115 private _registry: MapOf<TraceSource> = {};
private _listeners: MapOf<(source: TraceSource) => void> = {};
cin
minor refactoring of TraceSource, code linting
r53 private _nextCookie: number = 1;
cin
corrected code to support ts strict mode...
r115 get(id: string): TraceSource {
cin
minor refactoring of TraceSource, code linting
r53 argumentNotNull(id, "id");
if (this._registry[id])
return this._registry[id];
cin
Fixed circular dependency TraceSource<->Registry
r148 else
throw new Error("The specified trace source doesn't exists");
}
cin
minor refactoring of TraceSource, code linting
r53
cin
Fixed circular dependency TraceSource<->Registry
r148 has(id: string) {
return !!this._registry[id];
cin
minor refactoring of TraceSource, code linting
r53 }
add(id: any, source: TraceSource) {
argumentNotNull(id, "id");
argumentNotNull(source, "source");
this._registry[id] = source;
this._onNewSource(source);
}
_onNewSource(source: TraceSource) {
for (const i in this._listeners)
this._listeners[i].call(null, source);
}
on(handler: (source: TraceSource) => void): IDestroyable {
argumentNotNull(handler, "handler");
const me = this;
const cookie = this._nextCookie++;
this._listeners[cookie] = handler;
for (const i in this._registry)
handler(this._registry[i]);
return {
destroy() {
delete me._listeners[cookie];
}
};
}
}