mirror of
https://github.com/the-djmaze/snappymail.git
synced 2024-12-31 03:52:01 +08:00
Cleanup createCommand()
This commit is contained in:
parent
954de06f86
commit
a15454fd15
1 changed files with 8 additions and 17 deletions
|
@ -259,23 +259,15 @@ export const
|
|||
* @param {(Function|boolean|null)=} fCanExecute = true
|
||||
* @returns {Function}
|
||||
*/
|
||||
createCommand = (fExecute, fCanExecute = true) => {
|
||||
let fResult = fExecute
|
||||
? (...args) => {
|
||||
if (fResult && fResult.canExecute && fResult.canExecute()) {
|
||||
fExecute.apply(null, args);
|
||||
}
|
||||
createCommand = (fExecute, fCanExecute) => {
|
||||
let fResult = () => {
|
||||
fResult.canExecute() && fExecute.call(null);
|
||||
return false;
|
||||
} : ()=>0;
|
||||
};
|
||||
fResult.enabled = ko.observable(true);
|
||||
fResult.isCommand = true;
|
||||
|
||||
if (isFunction(fCanExecute)) {
|
||||
fResult.canExecute = koComputable(() => fResult && fResult.enabled() && fCanExecute.call(null));
|
||||
} else {
|
||||
fResult.canExecute = koComputable(() => fResult && fResult.enabled() && !!fCanExecute);
|
||||
}
|
||||
|
||||
fResult.canExecute = isFunction(fCanExecute)
|
||||
? koComputable(() => fResult.enabled() && fCanExecute())
|
||||
: fResult.enabled;
|
||||
return fResult;
|
||||
},
|
||||
|
||||
|
@ -350,11 +342,10 @@ export const
|
|||
fn = (...args) => fn.enabled() && fn.canExecute() && command.apply(thisArg, args);
|
||||
|
||||
// fn.__realCanExecute = canExecute;
|
||||
// fn.isCommand = true;
|
||||
|
||||
fn.enabled = ko.observable(true);
|
||||
|
||||
fn.canExecute = (typeof canExecute === 'function')
|
||||
fn.canExecute = isFunction(canExecute)
|
||||
? koComputable(() => fn.enabled() && canExecute.call(thisArg, thisArg))
|
||||
: koComputable(() => fn.enabled());
|
||||
|
||||
|
|
Loading…
Reference in a new issue