<commit_before>/// <reference path="../_references.d.ts" />
/// <reference path="base.d.ts" />

interface KnockoutBindingHandlers {
    date: KnockoutBindingHandler;
    command: KnockoutBindingHandler;
    loader: KnockoutBindingHandler;
    limitedText: KnockoutBindingHandler;
    pad: KnockoutBindingHandler;
    formatText: KnockoutBindingHandler;
    filesize: KnockoutBindingHandler;
    src: KnockoutBindingHandler;
    href: KnockoutBindingHandler;
    mailto: KnockoutBindingHandler;
    classes: KnockoutBindingHandler;
    on: KnockoutBindingHandler;
    hover: KnockoutBindingHandler;
    toggle: KnockoutBindingHandler;
    toggleClass: KnockoutBindingHandler;
    dblclick: KnockoutBindingHandler;
    editable: KnockoutBindingHandler;
    clipboard: KnockoutBindingHandler;
    debug: KnockoutBindingHandler;
    console: KnockoutBindingHandler;
}

module spa {
    //#region Command Bindings

    ko.bindingHandlers.command = {
        init: function (element: HTMLElement, valueAccessor: () => any, allBindingsAccessor: () => any, viewModel: any, bindingContext: KnockoutBindingContext) {
            var value = valueAccessor(),
                commands = !!value.execute ? { click: value } : value,
                events = {},
                bindings = {};

            _.each(commands, function (command, event?) {
                if (ko.bindingHandlers[event]) {
                    bindings[event] = command.execute;
                } else {
                    events[event] = command.execute;
                }
            }),

            _.each(bindings, function (bindingValue, binding?) {
                ko.bindingHandlers[binding].init(element, spa.createAccessor(bindingValue), allBindingsAccessor, viewModel, bindingContext);
            });

            if (_.size(events) > 0)
                ko.bindingHandlers.event.init(element, spa.createAccessor(events), allBindingsAccessor, viewModel, bindingContext);
        },
        update: function (element: HTMLElement, valueAccessor: () => any, allBindingsAccessor: () => any, viewModel: any, bindingContext: KnockoutBindingContext) {
            var value = valueAccessor(),
                commands = !!value.execute ? { click: value } : value,
                result = true;

            _.find(commands, function (command) {
                result = command.canExecute();
                return !result;
            });<commit_msg>Fix issue with Command binding handler<commit_after>/// <reference path="../_references.d.ts" />
/// <reference path="base.d.ts" />

interface KnockoutBindingHandlers {
    date: KnockoutBindingHandler;
    command: KnockoutBindingHandler;
    loader: KnockoutBindingHandler;
    limitedText: KnockoutBindingHandler;
    pad: KnockoutBindingHandler;
    formatText: KnockoutBindingHandler;
    filesize: KnockoutBindingHandler;
    src: KnockoutBindingHandler;
    href: KnockoutBindingHandler;
    mailto: KnockoutBindingHandler;
    classes: KnockoutBindingHandler;
    on: KnockoutBindingHandler;
    hover: KnockoutBindingHandler;
    toggle: KnockoutBindingHandler;
    toggleClass: KnockoutBindingHandler;
    dblclick: KnockoutBindingHandler;
    editable: KnockoutBindingHandler;
    clipboard: KnockoutBindingHandler;
    debug: KnockoutBindingHandler;
    console: KnockoutBindingHandler;
}

module spa {
    //#region Command Bindings

    ko.bindingHandlers.command = {
        init: function (element: HTMLElement, valueAccessor: () => any, allBindingsAccessor: () => any, viewModel: any, bindingContext: KnockoutBindingContext) {
            var value = valueAccessor(),
                commands = !!value.execute ? { click: value } : value,
                events = {},
                bindings = {};

            _.each(commands, function (command, event?) {
                if (ko.bindingHandlers[event]) {
                    bindings[event] = _.bind(command.execute, command);
                } else {
                    events[event] = _.bind(command.execute, command);
                }
            }),

            _.each(bindings, function (bindingValue, binding?) {
                ko.bindingHandlers[binding].init(element, spa.createAccessor(bindingValue), allBindingsAccessor, viewModel, bindingContext);
            });

            if (_.size(events) > 0)
                ko.bindingHandlers.event.init(element, spa.createAccessor(events), allBindingsAccessor, viewModel, bindingContext);
        },
        update: function (element: HTMLElement, valueAccessor: () => any, allBindingsAccessor: () => any, viewModel: any, bindingContext: KnockoutBindingContext) {
            var value = valueAccessor(),
                commands = !!value.execute ? { click: value } : value,
                result = true;

            _.find(commands, function (command) {
                result = command.canExecute();
                return !result;
            });
{'fraction_non_alphanumeric': 0.10365231585390737, 'fraction_numerical': 0.00040807998367680065, 'mean_word_length': 2.5991189427312777, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3463657', 'n_tokens_mistral': 1310, 'n_tokens_neox': 1221, 'n_words': 271}