snappymail/dev/Knoin/AbstractScreen.js

40 lines
705 B
JavaScript
Raw Normal View History

2021-07-22 03:34:17 +08:00
import { isArray, arrayLength } from 'Common/Utils';
2019-07-05 03:19:24 +08:00
export class AbstractScreen {
constructor(screenName, viewModels = []) {
this.__cross = null;
this.screenName = screenName;
this.viewModels = isArray(viewModels) ? viewModels : [];
2016-07-07 07:11:13 +08:00
}
/**
* @returns {?Array)}
*/
routes() {
return null;
}
/*
onBuild(viewModelDom) {}
onShow() {}
onHide() {}
__started
__builded
*/
2016-07-07 07:11:13 +08:00
/**
* @returns {void}
*/
onStart() {
const routes = this.routes();
if (arrayLength(routes)) {
let route = new Crossroads(),
fMatcher = (this.onRoute || (()=>0)).bind(this);
2022-09-08 16:07:27 +08:00
routes.forEach(item => item && (route.addRoute(item[0], fMatcher).rules = item[1]));
this.__cross = route;
2016-07-07 07:11:13 +08:00
}
}
}