mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-03 22:47:03 +03:00
Code refactoring (2) (es5 -> es2015)
This commit is contained in:
parent
38a1041a73
commit
a2308e251b
23 changed files with 760 additions and 821 deletions
|
|
@ -1,83 +0,0 @@
|
|||
|
||||
var
|
||||
_ = require('_'),
|
||||
crossroads = require('crossroads'),
|
||||
|
||||
Utils = require('Common/Utils');
|
||||
|
||||
/**
|
||||
* @param {string} sScreenName
|
||||
* @param {?=} aViewModels = []
|
||||
* @constructor
|
||||
*/
|
||||
function AbstractScreen(sScreenName, aViewModels)
|
||||
{
|
||||
this.sScreenName = sScreenName;
|
||||
this.aViewModels = Utils.isArray(aViewModels) ? aViewModels : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @type {Array}
|
||||
*/
|
||||
AbstractScreen.prototype.oCross = null;
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
AbstractScreen.prototype.sScreenName = '';
|
||||
|
||||
/**
|
||||
* @type {Array}
|
||||
*/
|
||||
AbstractScreen.prototype.aViewModels = [];
|
||||
|
||||
/**
|
||||
* @returns {Array}
|
||||
*/
|
||||
AbstractScreen.prototype.viewModels = function()
|
||||
{
|
||||
return this.aViewModels;
|
||||
};
|
||||
|
||||
/**
|
||||
* @returns {string}
|
||||
*/
|
||||
AbstractScreen.prototype.screenName = function()
|
||||
{
|
||||
return this.sScreenName;
|
||||
};
|
||||
|
||||
AbstractScreen.prototype.routes = function()
|
||||
{
|
||||
return null;
|
||||
};
|
||||
|
||||
/**
|
||||
* @returns {?Object}
|
||||
*/
|
||||
AbstractScreen.prototype.__cross = function()
|
||||
{
|
||||
return this.oCross;
|
||||
};
|
||||
|
||||
AbstractScreen.prototype.__start = function()
|
||||
{
|
||||
var
|
||||
aRoutes = this.routes(),
|
||||
oRoute = null,
|
||||
fMatcher = null;
|
||||
|
||||
if (Utils.isNonEmptyArray(aRoutes))
|
||||
{
|
||||
fMatcher = _.bind(this.onRoute || Utils.noop, this);
|
||||
oRoute = crossroads.create();
|
||||
|
||||
_.each(aRoutes, function(aItem) {
|
||||
oRoute.addRoute(aItem[0], fMatcher).rules = aItem[1];
|
||||
});
|
||||
|
||||
this.oCross = oRoute;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = AbstractScreen;
|
||||
66
dev/Knoin/AbstractScreen.jsx
Normal file
66
dev/Knoin/AbstractScreen.jsx
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
|
||||
import _ from '_';
|
||||
import crossroads from 'crossroads';
|
||||
import {isArray, isNonEmptyArray, noop} from 'Common/Utils';
|
||||
|
||||
class AbstractScreen
|
||||
{
|
||||
constructor(screenName, viewModels = [])
|
||||
{
|
||||
this.oCross = null;
|
||||
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();
|
||||
|
||||
_.each(routes, (aItem) => {
|
||||
route.addRoute(aItem[0], fMatcher).rules = aItem[1];
|
||||
});
|
||||
|
||||
this.oCross = route;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export {AbstractScreen, AbstractScreen as default};
|
||||
Loading…
Add table
Add a link
Reference in a new issue