2018-02-22 00:08:34 +02:00
|
|
|
class NavService {
|
|
|
|
static async go(routeName) {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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_ = [];
|
|
|
|
|
2019-07-29 15:43:53 +02:00
|
|
|
module.exports = NavService;
|