Add asserts folder

Add @command decorator
This commit is contained in:
RainLoop Team 2016-09-03 02:19:37 +03:00
parent a60ffc06e1
commit 1526130bfc
44 changed files with 300 additions and 264 deletions

24
dev/External/ko.js vendored
View file

@ -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');