mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-12 08:54:00 +02:00
34 lines
678 B
JavaScript
34 lines
678 B
JavaScript
class NavService {
|
|
static async go(routeName) {
|
|
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) {
|
|
for (let i = this.handlers_.length - 1; i >= 0; i--) {
|
|
const h = this.handlers_[i];
|
|
if (h === handler) return;
|
|
}
|
|
|
|
return this.handlers_.push(handler);
|
|
}
|
|
|
|
static removeHandler(hanlder) {
|
|
for (let i = this.handlers_.length - 1; i >= 0; i--) {
|
|
const h = this.handlers_[i];
|
|
if (h === hanlder) this.handlers_.splice(i, 1);
|
|
}
|
|
}
|
|
}
|
|
|
|
NavService.handlers_ = [];
|
|
|
|
module.exports = NavService;
|