vue-files-preview-inno
Version:
A tool for previewing files such as doc, excel, pdf, image, markdown, txt, audio, and video and so on.
56 lines (55 loc) • 1.33 kB
JavaScript
class n {
constructor(t) {
this.context = t || this, this.hooks = [];
}
/**
* Adds a function to be run before a hook completes
* @example this.content.register(function(){...});
*/
register() {
for (var t = 0; t < arguments.length; ++t)
if (typeof arguments[t] == "function")
this.hooks.push(arguments[t]);
else
for (var s = 0; s < arguments[t].length; ++s)
this.hooks.push(arguments[t][s]);
}
/**
* Removes a function
* @example this.content.deregister(function(){...});
*/
deregister(t) {
let s;
for (let o = 0; o < this.hooks.length; o++)
if (s = this.hooks[o], s === t) {
this.hooks.splice(o, 1);
break;
}
}
/**
* Triggers a hook to run all functions
* @example this.content.trigger(args).then(function(){...});
*/
trigger() {
var t = arguments, s = this.context, o = [];
return this.hooks.forEach(function(e) {
try {
var r = e.apply(s, t);
} catch (h) {
console.log(h);
}
r && typeof r.then == "function" && o.push(r);
}), Promise.all(o);
}
// Adds a function to be run before a hook completes
list() {
return this.hooks;
}
clear() {
return this.hooks = [];
}
}
export {
n as default
};
//# sourceMappingURL=hook.mjs.map