<commit_before>define(['knockout', 'underscore'], function (ko, _) {
    /**
    * A viewmodel used for generic widgets
    *
    * @constructor
    * @name WidgetViewModel
    *
    * @param  {string} params - a configuration object
    */
    var WidgetViewModel = function(params) {
        var self = this;
        this.state = params.state || 'form';
        this.expanded = params.expanded || ko.observable(false);
        this.value = params.value || ko.observable(null);
        this.formData = params.formData || new FormData();
        this.form = params.form || null;
        this.tile = params.tile || null;
        this.results = params.results || null;
        this.displayValue = ko.computed(function() {
            return ko.unwrap(self.value);
        });
        this.disabled = params.disabled || ko.observable(false);
        this.node = params.node || null;
        this.configForm = params.configForm || false;
        this.config = params.config || ko.observable({});
        this.configObservables = params.configObservables || {};
        this.configKeys = params.configKeys || [];
        this.configKeys.push('label');
        if (typeof this.config !== 'function') {
            this.config = ko.observable(this.config);
        }

        var subscribeConfigObservable = function (obs, key) {
            self[key] = obs;

            self[key].subscribe(function(val) {
                var configObj = self.config();
                configObj[key] = val;
                self.config(configObj);
            });

            self.config.subscribe(function(val) {
                if (val[key] !== self[key]()) {
                    self[key](val[key]);
                }
            });
        };
        _.each(this.configObservables, subscribeConfigObservable);
        _.each(this.configKeys, function(key) {
            var obs = ko.observable(self.config()[key]);
            subscribeConfigObservable(obs, key);
        });
    };
    return WidgetViewModel;
});
<commit_msg>ensuring only one widget per tile can be expanded re: #2006<commit_after>define(['knockout', 'underscore', 'uuid'], function (ko, _, uuid) {
    /**
    * A viewmodel used for generic widgets
    *
    * @constructor
    * @name WidgetViewModel
    *
    * @param  {string} params - a configuration object
    */
    var WidgetViewModel = function(params) {
        var self = this;
        this.state = params.state || 'form';
        var expanded = params.expanded || ko.observable(false);
        var nodeid = params.node ? params.node.nodeid : uuid.generate();
        this.expanded = ko.computed({
            read: function() {
                return nodeid === expanded();
            },
            write: function(val) {
                if (val) {
                    expanded(nodeid);
                } else {
                    expanded(false);
                }
            }
        })
        this.value = params.value || ko.observable(null);
        this.formData = params.formData || new FormData();
        this.form = params.form || null;
        this.tile = params.tile || null;
        this.results = params.results || null;
        this.displayValue = ko.computed(function() {
            return ko.unwrap(self.value);
        });
        this.disabled = params.disabled || ko.observable(false);
        this.node = params.node || null;
        this.configForm = params.configForm || false;
        this.config = params.config || ko.observable({});
        this.configObservables = params.configObservables || {};
        this.configKeys = params.configKeys || [];
        this.configKeys.push('label');
        if (typeof this.config !== 'function') {
            this.config = ko.observable(this.config);
        }

        var subscribeConfigObservable = function (obs, key) {
            self[key] = obs;

            self[key].subscribe(function(val) {
                var configObj = self.config();
                configObj[key] = val;
                self.config(configObj);
            });

            self.config.subscribe(function(val) {
                if (val[key] !== self[key]()) {
                    self[key](val[key]);
                }
            });
        };
        _.each(this.configObservables, subscribeConfigObservable);
        _.each(this.configKeys, function(key) {
            var obs = ko.observable(self.config()[key]);
            subscribeConfigObservable(obs, key);
        });
    };
    return WidgetViewModel;
});

{'fraction_non_alphanumeric': 0.1347738917353531, 'fraction_numerical': 0.0008910670527957229, 'mean_word_length': 1.8526048284625158, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3419678', 'n_tokens_mistral': 1231, 'n_tokens_neox': 1199, 'n_words': 240}