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.
40 lines
1.4 KiB
TypeScript
40 lines
1.4 KiB
TypeScript
4 years ago
|
export class Page {
|
||
3 years ago
|
constructor(public name: string | string[], public autoload: boolean, public afterLoading, public beforeLoading) {
|
||
4 years ago
|
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 afterLoading !== 'function' && afterLoading != null) {
|
||
|
// eslint-disable-next-line quotes
|
||
|
throw new Error(`'afterLoading' should be a function`);
|
||
|
}
|
||
|
if (typeof beforeLoading !== 'function' && beforeLoading != null) {
|
||
|
// eslint-disable-next-line quotes
|
||
|
throw new Error(`'beforeLoading' should be a function`);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
3 years ago
|
isNameMatch(name: string) {
|
||
3 years ago
|
if (typeof this.name === 'string') return this.name === name;
|
||
|
if (this.name instanceof Array) return this.name.includes(name);
|
||
4 years ago
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export class NamedPage extends Page {
|
||
3 years ago
|
constructor(name: string | string[], afterLoading = null, beforeLoading = null) {
|
||
4 years ago
|
super(name, false, afterLoading, beforeLoading);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export class AutoloadPage extends Page {
|
||
3 years ago
|
constructor(name: string | string[], afterLoading = null, beforeLoading = null) {
|
||
4 years ago
|
super(name, true, afterLoading, beforeLoading);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
window.Hydro.NamedPage = NamedPage;
|
||
|
window.Hydro.AutoloadPage = AutoloadPage;
|