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

/********************************/
/** vm-Update Bindings: colums **/
/********************************/
gridState.processors['vm-update-bindings-columns'] = {
    watches: ['sort', 'columns', 'space'],
    init: function (model) {
        model.vm.columns = ko.observableArray();
    },
    runs: function (options) {
        if (!options.model.space || !options.model.space.width) {
            return;
        }
        if (options.model.logging) {
            console.log('Updating the column bindings');
        }
        var i = 0;

        var columns = options.model.columns;
        var temp = options.model.vm.columns();
        var numBefore = temp.length;
        var numNow = columns.length;
        if (numBefore > numNow) {
            temp = temp.slice(0, numNow);
        }
        else if (numBefore < numNow) {
            for (i = numBefore; i < numNow; i++) {
                temp[i] = ko.observable();
            }
        }

        for (i = 0; i < numNow; i++) {
            var column = columns[i];
            var colBefore = options.cache[column.id];
            var colNow = JSON.stringify(column);
            var newObj = JSON.parse(colNow);
            addColumnFunctions(newObj, options);
            temp[i](newObj);
            options.cache[column.id] = colNow;
        }
        if (numBefore !== numNow) {
            options.model.vm.columns(temp);
        }
    }
};

function addColumnFunctions(col, options) {
    if (col.type === 'select') {
        col.toggleSelectAll = function (grid) {
            return function () {
                grid.process({ selection: { all: !options.model.ui.allSelected } });
                return true;
            };
        };
    }
}<commit_msg>Column KO Bindings now updates when the order of columns change even when the number of columns stays the same<commit_after>/* eslint no-unused-vars: 0 */

/********************************/
/** vm-Update Bindings: colums **/
/********************************/
gridState.processors['vm-update-bindings-columns'] = {
    watches: ['sort', 'columns', 'space'],
    init: function (model) {
        model.vm.columns = ko.observableArray();
    },
    runs: function (options) {
        if (!options.model.space || !options.model.space.width) {
            return;
        }
        if (options.model.logging) {
            console.log('Updating the column bindings');
        }
        var i = 0;

        var columns = options.model.columns;
        var temp = options.model.vm.columns();
        var numBefore = temp.length;
        var numNow = columns.length;
        if (numBefore > numNow) {
            temp = temp.slice(0, numNow);
        }
        else if (numBefore < numNow) {
            for (i = numBefore; i < numNow; i++) {
                temp[i] = ko.observable();
            }
        }

        for (i = 0; i < numNow; i++) {
            var column = columns[i];
            var colBefore = options.cache[column.id];
            var colNow = JSON.stringify(column);
            var newObj = JSON.parse(colNow);
            addColumnFunctions(newObj, options);
            temp[i](newObj);
            options.cache[column.id] = colNow;
        }
    
        options.model.vm.columns(temp);
    }
};

function addColumnFunctions(col, options) {
    if (col.type === 'select') {
        col.toggleSelectAll = function (grid) {
            return function () {
                grid.process({ selection: { all: !options.model.ui.allSelected } });
                return true;
            };
        };
    }
}
{'fraction_non_alphanumeric': 0.1682424916573971, 'fraction_numerical': 0.002224694104560623, 'mean_word_length': 1.8256087981146898, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, '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': '1074110', 'n_tokens_mistral': 1029, 'n_tokens_neox': 1010, 'n_words': 230}