<commit_before>/* eslint no-unused-vars: 0 */

var selectedObservables = {};

/******************************/
/** vm-Handlebars: data **/
/******************************/
gridState.processors['vm-handlebars-data'] = {
    watches: ['data', 'selection'],
    init: function (model) {
        if (!model.vm.data) {
            model.vm.data = ko.observableArray();
            model.vm.data.loaded = ko.observable(false);
            model.ui.hb_tbody = ko.observable('');
        }
    },
    runs: function (options) {
        options.cache.templates = options.cache.templates || {};

        if (options.model.logging) {
            console.log('Updating the handlebar data template');
        }

        if (!options.cache.namespace) {
            options.cache.namespace = 'NSSG_' + Math.floor(Math.random() * 99999);
            options.cache.jsContext = {};
            window[options.cache.namespace] = options.cache.jsContext;
        }

        options.cache.jsContext.toggleSelect = function (rowIdentity, isSelected, e) {
            console.log('Setting ' + rowIdentity + ' to ' + (!isSelected ? 'selected' : 'deselected'));
            var rowSelect = {};
            rowSelect[rowIdentity] = !isSelected;
            setTimeout(function () {
                options.model.vm.process({ selection: rowSelect });
            }, 1);
            if (e) {
                $('input', $(e).parent()).prop('checked', !isSelected);
            }
        };

        options.cache.jsContext.invokeAction = function (rowIdentity, index) {
            var action = options.model.ui.actions[index];
            var row = findFirst(options.model.data, { $identity: rowIdentity });
            if (action && row) {
                if (action.onClick) {
                    action.onClick(row.raw);
                }
            }
            else {
                console.warn("action or row data couldn't be matched");
            }
        };

        var templateParts = [];
        templateParts.push('{{#each data as |row key|}}');
        templateParts.push("<tr class='nssg-tbody-tr'>");
        templateParts = templateParts.concat(options.model.columns.map(function (col) {
            if (!col.isVisible) {
                return '';
            }
            return "<td class='nssg-td nssg-td-" + col.type + "'>" +
                templates[col.type + '_hb'].replace(/\{\{value\}\}/g, '{{' + col.id + '}}') +
                '</td>';
        }));
        templateParts.push("<td class='nssg-td nssg-td-gutter'></td>");
        templateParts.push('</tr>');
        templateParts.push('{{/each}}');
        var template = templateParts.join('\n');
        var compiledTemplate = options.cache.templates[template];
        if (!compiledTemplate) {
            compiledTemplate = Handlebars.compile(template);
            options.cache.templates[template] = compiledTemplate;
        }

        var actions = options.model.ui.actions.map(function (action, index) {
            return { css: action.css, index: index };
        });
        var context = {
            jsContext: options.cache.namespace,
            data: options.model.data,
            actions: actions
        };
<commit_msg>Improve speed of user feedback when selecting row in single select mode with large page sizes<commit_after>/* eslint no-unused-vars: 0 */

var selectedObservables = {};

/******************************/
/** vm-Handlebars: data **/
/******************************/
gridState.processors['vm-handlebars-data'] = {
    watches: ['data', 'selection'],
    init: function (model) {
        if (!model.vm.data) {
            model.vm.data = ko.observableArray();
            model.vm.data.loaded = ko.observable(false);
            model.ui.hb_tbody = ko.observable('');
        }
    },
    runs: function (options) {
        options.cache.templates = options.cache.templates || {};

        if (options.model.logging) {
            console.log('Updating the handlebar data template');
        }

        if (!options.cache.namespace) {
            options.cache.namespace = 'NSSG_' + Math.floor(Math.random() * 99999);
            options.cache.jsContext = {};
            window[options.cache.namespace] = options.cache.jsContext;
        }

        options.cache.jsContext.toggleSelect = function (rowIdentity, isSelected, e) {
            console.log('Setting ' + rowIdentity + ' to ' + (!isSelected ? 'selected' : 'deselected'));
            var rowSelect = {};
            rowSelect[rowIdentity] = !isSelected;
            setTimeout(function () {
                options.model.vm.process({ selection: rowSelect });
            }, 1);
            if (e) {
                $('input', $(e).parent()).prop('checked', !isSelected);
            }
            if (options.model.ui.selectMode === 'single') {
                for (var key in options.model.selection) {
                    var id = options.cache.namespace + '_' + key;
                    var $row = $('#' + id);
                    var $select = $('.nssg-td-select input', $row);
                    $select.prop('checked', false);
                }
            }
        };

        options.cache.jsContext.invokeAction = function (rowIdentity, index) {
            var action = options.model.ui.actions[index];
            var row = findFirst(options.model.data, { $identity: rowIdentity });
            if (action && row) {
                if (action.onClick) {
                    action.onClick(row.raw);
                }
            }
            else {
                console.warn("action or row data couldn't be matched");
            }
        };

        var templateParts = [];
        templateParts.push('{{#each data as |row key|}}');
        templateParts.push("<tr class='nssg-tbody-tr' id='" + options.cache.namespace + "_{{$identity}}'>");
        templateParts = templateParts.concat(options.model.columns.map(function (col) {
            if (!col.isVisible) {
                return '';
            }
            return "<td class='nssg-td nssg-td-" + col.type + "'>" +
                templates[col.type + '_hb'].replace(/\{\{value\}\}/g, '{{' + col.id + '}}') +
                '</td>';
        }));
        templateParts.push("<td class='nssg-td nssg-td-gutter'></td>");
        templateParts.push('</tr>');
        templateParts.push('{{/each}}');
        var template = templateParts.join('\n');
        var compiledTemplate = options.cache.templates[template];
        if (!compiledTemplate) {
            compiledTemplate = Handlebars.compile(template);
            options.cache.templates[template] = compiledTemplate;
        }

        var actions = options.model.ui.actions ? options.model.ui.actions.map(function (action, index) {
            return { css: action.css, index: index };
        }) : [];
        var context = {
            jsContext: options.cache.namespace,
            data: options.model.data,
            actions: actions
        };

{'fraction_non_alphanumeric': 0.1676267281105991, 'fraction_numerical': 0.0020161290322580645, 'mean_word_length': 1.8793532338308458, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '956263', 'n_tokens_mistral': 1911, 'n_tokens_neox': 1862, 'n_words': 349}