2021-01-22 19:41:11 +02:00
|
|
|
export default class NavService {
|
|
|
|
|
2023-06-30 11:30:29 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/ban-types -- Old code before rule was applied
|
2021-01-22 19:41:11 +02:00
|
|
|
public static dispatch: Function = () => {};
|
2023-06-30 11:30:29 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/ban-types -- Old code before rule was applied
|
2021-01-22 19:41:11 +02:00
|
|
|
private static handlers_: Function[] = [];
|
|
|
|
|
2021-06-19 18:32:36 +02:00
|
|
|
public static async go(routeName: string) {
|
2018-02-22 00:08:34 +02:00
|
|
|
if (this.handlers_.length) {
|
2020-03-14 01:46:14 +02:00
|
|
|
const r = await this.handlers_[this.handlers_.length - 1]();
|
2018-02-22 00:08:34 +02:00
|
|
|
if (r) return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.dispatch({
|
|
|
|
type: 'NAV_GO',
|
|
|
|
routeName: routeName,
|
2019-07-29 15:43:53 +02:00
|
|
|
});
|
2018-02-22 00:08:34 +02:00
|
|
|
}
|
|
|
|
|
2023-06-30 11:30:29 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/ban-types -- Old code before rule was applied
|
2021-06-19 18:32:36 +02:00
|
|
|
public static addHandler(handler: Function) {
|
2018-02-22 00:08:34 +02:00
|
|
|
for (let i = this.handlers_.length - 1; i >= 0; i--) {
|
|
|
|
const h = this.handlers_[i];
|
|
|
|
if (h === handler) return;
|
|
|
|
}
|
|
|
|
|
2021-01-22 19:41:11 +02:00
|
|
|
this.handlers_.push(handler);
|
2018-02-22 00:08:34 +02:00
|
|
|
}
|
|
|
|
|
2023-06-30 11:30:29 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/ban-types -- Old code before rule was applied
|
2021-06-19 18:32:36 +02:00
|
|
|
public static removeHandler(hanlder: Function) {
|
2018-02-22 00:08:34 +02:00
|
|
|
for (let i = this.handlers_.length - 1; i >= 0; i--) {
|
|
|
|
const h = this.handlers_[i];
|
|
|
|
if (h === hanlder) this.handlers_.splice(i, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|