isArray to native Array.isArray

isUnd(*) to native undefined === *
isFunc to native typeof * === 'function'
isObject to native typeof * === 'object'
microtime() to native Date().getTime();
noop to native ()=>{}
noopFalse to native ()=>false
noopTrue to native ()=>true
boolToAjax to native *?'1':'0'
Underscore.js to native
This commit is contained in:
djmaze 2020-07-29 21:49:41 +02:00
parent fa39c7ecba
commit ea48f5060b
72 changed files with 551 additions and 775 deletions

View file

@ -1,4 +1,9 @@
import { isArray, disposeObject } from 'Common/Utils';
function disposeOne(disposable) {
if (disposable && 'function' === typeof disposable.dispose) {
disposable.dispose();
}
}
export class AbstractModel {
sModelName = '';
@ -12,7 +17,7 @@ export class AbstractModel {
}
regDisposables(value) {
if (isArray(value)) {
if (Array.isArray(value)) {
value.forEach((item) => {
this.disposables.push(item);
});
@ -22,6 +27,9 @@ export class AbstractModel {
}
onDestroy() {
disposeObject(this);
if (Array.isArray(this.disposables)) {
this.disposables.forEach(disposeOne);
}
Object.values(this).forEach(disposeOne);
}
}

View file

@ -1,5 +1,5 @@
import crossroads from 'crossroads';
import { isArray, isNonEmptyArray, noop } from 'Common/Utils';
import { isNonEmptyArray } from 'Common/Utils';
export class AbstractScreen {
oCross = null;
@ -8,7 +8,7 @@ export class AbstractScreen {
constructor(screenName, viewModels = []) {
this.sScreenName = screenName;
this.aViewModels = isArray(viewModels) ? viewModels : [];
this.aViewModels = Array.isArray(viewModels) ? viewModels : [];
}
/**
@ -48,7 +48,7 @@ export class AbstractScreen {
const routes = this.routes();
if (isNonEmptyArray(routes)) {
fMatcher = (this.onRoute || noop).bind(this);
fMatcher = (this.onRoute || (()=>{})).bind(this);
route = crossroads.create();
routes.forEach((item) => {

View file

@ -1,4 +1,3 @@
import _ from '_';
import $ from '$';
import ko from 'ko';
import hasher from 'hasher';
@ -8,7 +7,7 @@ import { Magics } from 'Common/Enums';
import { runHook } from 'Common/Plugins';
import { $htmlCL, VIEW_MODELS, popupVisibilityNames } from 'Common/Globals';
import { isArray, isUnd, pString, log, isFunc, createCommandLegacy, delegateRun, isNonEmptyArray } from 'Common/Utils';
import { pString, log, createCommandLegacy, delegateRun, isNonEmptyArray } from 'Common/Utils';
let currentScreen = null,
defaultScreenName = '';
@ -95,7 +94,7 @@ export function routeOn() {
* @returns {?Object}
*/
export function screen(screenName) {
return screenName && !isUnd(SCREENS[screenName]) ? SCREENS[screenName] : null;
return screenName && undefined !== SCREENS[screenName] ? SCREENS[screenName] : null;
}
/**
@ -317,7 +316,7 @@ export function screenOnRoute(screenName, subPart) {
delegateRun(vmScreen, 'onBuild');
}
_.defer(() => {
setTimeout(() => {
// hide screen
if (currentScreen && !isSameScreen) {
delegateRun(currentScreen, 'onHide');
@ -389,7 +388,7 @@ export function screenOnRoute(screenName, subPart) {
if (cross) {
cross.parse(subPart);
}
});
}, 1);
}
}
}
@ -470,7 +469,7 @@ function viewDecorator({ name, type, templateID }) {
return (target) => {
if (target) {
if (name) {
if (isArray(name)) {
if (Array.isArray(name)) {
target.__names = name;
} else {
target.__names = [name];
@ -509,7 +508,7 @@ function commandDecorator(canExecute = true) {
}
const value = descriptor.value || descriptor.initializer(),
normCanExecute = isFunc(canExecute) ? canExecute : () => !!canExecute;
normCanExecute = typeof canExecute === 'function' ? canExecute : () => !!canExecute;
descriptor.value = function(...args) {
if (normCanExecute.call(this, this)) {
@ -531,23 +530,30 @@ function commandDecorator(canExecute = true) {
* @returns {Function}
*/
function settingsMenuKeysHandler($items) {
return _.throttle((event, handler) => {
const up = handler && 'up' === handler.shortcut;
// throttle
var t;
return (event, handler)=>{
if (!t) {
t = setTimeout(()=>{
const up = handler && 'up' === handler.shortcut;
if (event && $items.length) {
let index = $items.index($items.filter('.selected'));
if (up && 0 < index) {
index -= 1;
} else if (!up && index < $items.length - 1) {
index += 1;
}
if (event && $items.length) {
let index = $items.index($items.filter('.selected'));
if (up && 0 < index) {
index -= 1;
} else if (!up && index < $items.length - 1) {
index += 1;
}
const resultHash = $items.eq(index).attr('href');
if (resultHash) {
setHash(resultHash, false, true);
}
const resultHash = $items.eq(index).attr('href');
if (resultHash) {
setHash(resultHash, false, true);
}
}
t = 0;
}, Magics.Time200ms);
}
}, Magics.Time200ms);
};
}
export {