snappymail/dev/Knoin/AbstractScreen.js

57 lines
913 B
JavaScript
Raw Normal View History

2019-07-05 03:19:24 +08:00
export class AbstractScreen {
2016-09-10 06:38:16 +08:00
oCross = null;
sScreenName;
aViewModels;
2019-07-05 03:19:24 +08:00
constructor(screenName, viewModels = []) {
2016-07-07 07:11:13 +08:00
this.sScreenName = screenName;
this.aViewModels = Array.isArray(viewModels) ? viewModels : [];
2016-07-07 07:11:13 +08:00
}
/**
* @returns {Array}
*/
get viewModels() {
2016-07-07 07:11:13 +08:00
return this.aViewModels;
}
/**
* @returns {string}
*/
screenName() {
return this.sScreenName;
}
/**
* @returns {?Array)}
*/
routes() {
return null;
}
/**
* @returns {?Object}
*/
2020-10-02 18:40:33 +08:00
get __cross() {
2016-07-07 07:11:13 +08:00
return this.oCross;
}
/**
* @returns {void}
*/
onStart() {
if (!this.__started) {
this.__started = true;
const routes = this.routes();
if (Array.isNotEmpty(routes)) {
let route = new Crossroads(),
fMatcher = (this.onRoute || (()=>{})).bind(this);
routes.forEach(item => item && route && (route.addRoute(item[0], fMatcher).rules = item[1]));
this.oCross = route;
}
2016-07-07 07:11:13 +08:00
}
}
}