diff --git a/dev/Common/Utils.js b/dev/Common/Utils.js index f9d818fb4..cc5351d47 100644 --- a/dev/Common/Utils.js +++ b/dev/Common/Utils.js @@ -3,7 +3,8 @@ import { doc, elementById } from 'Common/Globals'; export const isArray = Array.isArray, - isNonEmptyArray = array => isArray(array) && array.length; + isNonEmptyArray = array => isArray(array) && array.length, + isFunction = v => typeof v === 'function'; /** * @param {*} value diff --git a/dev/External/ko.js b/dev/External/ko.js index 9354e27a1..92bd36173 100644 --- a/dev/External/ko.js +++ b/dev/External/ko.js @@ -1,10 +1,9 @@ import { i18n, i18nToNodes, trigger } from 'Common/Translator'; import { doc, createElement } from 'Common/Globals'; import { SaveSettingsStep } from 'Common/Enums'; -import { isNonEmptyArray } from 'Common/Utils'; +import { isNonEmptyArray, isFunction } from 'Common/Utils'; const - isFunction = v => typeof v === 'function', koValue = value => !ko.isObservable(value) && isFunction(value) ? value() : ko.unwrap(value); ko.bindingHandlers.tooltip = { diff --git a/dev/Knoin/AbstractModel.js b/dev/Knoin/AbstractModel.js index 5738f4908..6ac13305d 100644 --- a/dev/Knoin/AbstractModel.js +++ b/dev/Knoin/AbstractModel.js @@ -1,7 +1,7 @@ -import { isArray, addObservablesTo, addComputablesTo } from 'Common/Utils'; +import { isArray, isFunction, addObservablesTo, addComputablesTo } from 'Common/Utils'; function dispose(disposable) { - if (disposable && 'function' === typeof disposable.dispose) { + if (disposable && isFunction(disposable.dispose)) { disposable.dispose(); } } diff --git a/dev/Knoin/Knoin.js b/dev/Knoin/Knoin.js index 80168fb06..a061f0925 100644 --- a/dev/Knoin/Knoin.js +++ b/dev/Knoin/Knoin.js @@ -1,7 +1,7 @@ import ko from 'ko'; import { doc, $htmlCL } from 'Common/Globals'; -import { isNonEmptyArray } from 'Common/Utils'; +import { isNonEmptyArray, isFunction } from 'Common/Utils'; let currentScreen = null, defaultScreenName = ''; @@ -39,7 +39,7 @@ export function createCommand(fExecute, fCanExecute = true) { fResult.enabled = ko.observable(true); fResult.isCommand = true; - if (typeof fCanExecute === 'function') { + if (isFunction(fCanExecute)) { fResult.canExecute = ko.computed(() => fResult && fResult.enabled() && fCanExecute.call(null)); } else { fResult.canExecute = ko.computed(() => fResult && fResult.enabled() && !!fCanExecute); diff --git a/dev/View/Popup/Ask.js b/dev/View/Popup/Ask.js index 477ef40e8..41d505697 100644 --- a/dev/View/Popup/Ask.js +++ b/dev/View/Popup/Ask.js @@ -1,5 +1,6 @@ import { Scope } from 'Common/Enums'; import { i18n } from 'Common/Translator'; +import { isFunction } from 'Common/Utils'; import { AbstractViewPopup } from 'Knoin/AbstractViews'; @@ -32,17 +33,13 @@ class AskPopupView extends AbstractViewPopup { yesClick() { this.cancelCommand(); - if (typeof this.fYesAction === 'function') { - this.fYesAction.call(null); - } + isFunction(this.fYesAction) && this.fYesAction.call(null); } noClick() { this.cancelCommand(); - if (typeof this.fNoAction === 'function') { - this.fNoAction.call(null); - } + isFunction(this.fNoAction) && this.fNoAction.call(null); } /** diff --git a/dev/View/User/Login.js b/dev/View/User/Login.js index 3597e0482..d84524762 100644 --- a/dev/View/User/Login.js +++ b/dev/View/User/Login.js @@ -1,11 +1,8 @@ import ko from 'ko'; -import { - Notification -} from 'Common/Enums'; - +import { Notification } from 'Common/Enums'; import { ClientSideKeyName } from 'Common/EnumsUser'; - +import { Settings, SettingsGet } from 'Common/Globals'; import { getNotification, reload as translatorReload, convertLangName } from 'Common/Translator'; import { LanguageStore } from 'Stores/Language'; @@ -17,8 +14,6 @@ import Remote from 'Remote/User/Fetch'; import { decorateKoCommands, showScreenPopup } from 'Knoin/Knoin'; import { AbstractViewCenter } from 'Knoin/AbstractViews'; -import { Settings, SettingsGet } from 'Common/Globals'; - import { LanguagesPopupView } from 'View/Popup/Languages'; const @@ -131,8 +126,8 @@ class LoginUserView extends AbstractViewCenter { this.emailError(!email); this.passwordError(!pass); - this.formError(!valid); this.additionalCodeError(totp && !code); + this.formError(!valid); if (valid) { this.submitRequest(true);