1
0
Fork 0
freesewing/lib/hooks.ts

43 lines
988 B
TypeScript
Raw Normal View History

2018-07-17 14:16:17 +00:00
export class Hooks {
hooks: object;
all: string[];
2018-07-17 14:16:17 +00:00
constructor(app) {
this._hooks = {};
this.all = ['preRenderSvg', 'postRenderSvg'];
2018-07-17 14:16:17 +00:00
}
///** Add hook */
//on(hook, method): void {
// // This gets called from the pattern context
// // so 'this' is not actually this class
// let self = this.hooks;
// if(typeof self._hooks[method] === 'undefined') {
// self._hooks[hook] = [];
// }
// self._hooks[hook].push(method);
//}
2018-07-17 14:16:17 +00:00
list(hook): function[] {
if(typeof this._hooks[hook] === 'undefined') {
return false;
}
return this._hooks[hook];
}
attachPre (hook: string, obj: object): void {
this._attach('pre', hook, obj);
}
attachPost (hook: string, obj: object): void {
this._attach('post', hook, obj);
}
attach (hook: string, obj: object): void {
if(typeof this._hooks[hook] === 'undefined') return;
for(let func of this._hooks[hook]) {
obj.pre(hook, func);
}
}
}