mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-30 20:49:20 +03:00
Add asserts folder
Add @command decorator
This commit is contained in:
parent
a60ffc06e1
commit
1526130bfc
44 changed files with 300 additions and 264 deletions
24
dev/External/ko.js
vendored
24
dev/External/ko.js
vendored
|
|
@ -931,11 +931,29 @@ ko.bindingHandlers.command = {
|
|||
init: (element, fValueAccessor, fAllBindingsAccessor, viewModel, bindingContext) => {
|
||||
const
|
||||
jqElement = $(element),
|
||||
oCommand = fValueAccessor();
|
||||
command = fValueAccessor();
|
||||
|
||||
if (!oCommand || !oCommand.enabled || !oCommand.canExecute)
|
||||
if (!command || !command.isCommand)
|
||||
{
|
||||
throw new Error('You are not using command function');
|
||||
throw new Error('Value should be a command');
|
||||
}
|
||||
|
||||
if (!command.enabled)
|
||||
{
|
||||
command.enabled = ko.observable(true);
|
||||
}
|
||||
|
||||
if (!command.canExecute)
|
||||
{
|
||||
const __realCanExecute = command.__realCanExecute;
|
||||
if (_.isFunction(__realCanExecute))
|
||||
{
|
||||
command.canExecute = ko.computed(() => command.enabled() && __realCanExecute.call(viewModel, viewModel));
|
||||
}
|
||||
else
|
||||
{
|
||||
command.canExecute = ko.computed(() => command.enabled() && !!__realCanExecute);
|
||||
}
|
||||
}
|
||||
|
||||
jqElement.addClass('command');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue