2016-07-07 07:11:13 +08:00
|
|
|
|
|
|
|
import _ from '_';
|
|
|
|
import crossroads from 'crossroads';
|
|
|
|
import {isArray, isNonEmptyArray, noop} from 'Common/Utils';
|
|
|
|
|
|
|
|
class AbstractScreen
|
|
|
|
{
|
2016-09-10 06:38:16 +08:00
|
|
|
oCross = null;
|
|
|
|
sScreenName;
|
|
|
|
aViewModels;
|
|
|
|
|
2016-07-07 07:11:13 +08:00
|
|
|
constructor(screenName, viewModels = [])
|
|
|
|
{
|
|
|
|
this.sScreenName = screenName;
|
|
|
|
this.aViewModels = isArray(viewModels) ? viewModels : [];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns {Array}
|
|
|
|
*/
|
|
|
|
viewModels() {
|
|
|
|
return this.aViewModels;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
screenName() {
|
|
|
|
return this.sScreenName;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns {?Array)}
|
|
|
|
*/
|
|
|
|
routes() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns {?Object}
|
|
|
|
*/
|
|
|
|
__cross() {
|
|
|
|
return this.oCross;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
__start() {
|
|
|
|
let
|
|
|
|
route = null,
|
|
|
|
fMatcher = null;
|
|
|
|
const routes = this.routes();
|
|
|
|
|
|
|
|
if (isNonEmptyArray(routes))
|
|
|
|
{
|
|
|
|
fMatcher = _.bind(this.onRoute || noop, this);
|
|
|
|
route = crossroads.create();
|
|
|
|
|
2016-09-10 06:38:16 +08:00
|
|
|
_.each(routes, (item) => {
|
|
|
|
if (item && route)
|
|
|
|
{
|
|
|
|
route.addRoute(item[0], fMatcher).rules = item[1];
|
|
|
|
}
|
2016-07-07 07:11:13 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
this.oCross = route;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export {AbstractScreen, AbstractScreen as default};
|