You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
2.0 KiB
TypeScript
53 lines
2.0 KiB
TypeScript
type callback = (pagename: string, loadPage: (name: string) => Promise<any>) => any;
|
|
|
|
export class Page {
|
|
moduleName?: string;
|
|
autoload = false;
|
|
afterLoading?: callback;
|
|
beforeLoading?: callback;
|
|
constructor(pagename: string | string[], afterLoading: callback, beforeLoading: callback);
|
|
constructor(pagename: string | string[], moduleName: string, afterLoading: callback, beforeLoading: callback);
|
|
constructor(pagename: string | string[], ...args: any[]);
|
|
constructor(public name: string | string[], ...args: any[]) {
|
|
if (typeof args[0] === 'string') {
|
|
[this.moduleName, this.afterLoading, this.beforeLoading] = args;
|
|
} else {
|
|
[this.afterLoading, this.beforeLoading] = args;
|
|
}
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
if (typeof name !== 'string' && !(name instanceof Array)) {
|
|
// eslint-disable-next-line quotes
|
|
throw new Error(`'name' should be a string or string[]`);
|
|
}
|
|
if (typeof this.afterLoading !== 'function' && this.afterLoading != null) {
|
|
// eslint-disable-next-line quotes
|
|
throw new Error(`'afterLoading' should be a function`);
|
|
}
|
|
if (typeof this.beforeLoading !== 'function' && this.beforeLoading != null) {
|
|
// eslint-disable-next-line quotes
|
|
throw new Error(`'beforeLoading' should be a function`);
|
|
}
|
|
}
|
|
}
|
|
|
|
isNameMatch(name: string) {
|
|
if (typeof this.name === 'string') return this.name === name;
|
|
if (this.name instanceof Array) return this.name.includes(name);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
export class NamedPage extends Page { }
|
|
|
|
export class AutoloadPage extends Page {
|
|
constructor(pagename: string | string[], afterLoading: callback, beforeLoading: callback);
|
|
constructor(pagename: string | string[], moduleName: string, afterLoading: callback, beforeLoading: callback);
|
|
constructor(pagename: string | string[], ...args: any[]) {
|
|
super(pagename, ...args);
|
|
this.autoload = true;
|
|
}
|
|
}
|
|
|
|
window.Hydro.NamedPage = NamedPage;
|
|
window.Hydro.AutoloadPage = AutoloadPage;
|