2021-01-22 19:41:11 +02:00
|
|
|
export default class NavService {
|
|
|
|
|
|
|
|
public static dispatch: Function = () => {};
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|