mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-03 08:35:29 +02:00
34 lines
748 B
TypeScript
34 lines
748 B
TypeScript
export default class NavService {
|
|
|
|
public static dispatch: Function = () => {};
|
|
private static handlers_: Function[] = [];
|
|
|
|
static async go(routeName: string) {
|
|
if (this.handlers_.length) {
|
|
const r = await this.handlers_[this.handlers_.length - 1]();
|
|
if (r) return r;
|
|
}
|
|
|
|
this.dispatch({
|
|
type: 'NAV_GO',
|
|
routeName: routeName,
|
|
});
|
|
}
|
|
|
|
static addHandler(handler: Function) {
|
|
for (let i = this.handlers_.length - 1; i >= 0; i--) {
|
|
const h = this.handlers_[i];
|
|
if (h === handler) return;
|
|
}
|
|
|
|
this.handlers_.push(handler);
|
|
}
|
|
|
|
static removeHandler(hanlder: Function) {
|
|
for (let i = this.handlers_.length - 1; i >= 0; i--) {
|
|
const h = this.handlers_[i];
|
|
if (h === hanlder) this.handlers_.splice(i, 1);
|
|
}
|
|
}
|
|
}
|