<commit_before>jsHyphen.factory("HyphenDataModel", ['HyphenIndexDb', function (HyphenIndexDb) {
    var HyphenDataModel = function (model, name) {
        this.model = model;
        this.modelName = name;
        this.data = [];
        var self = this;
        _(model.indexes).each(function (index) {
            self["getBy" + index.name] = function (id) {
                if (!self["index" + index.name])
                    self["index" + index.name] = _(self.getData()).indexBy(function (data) {
                        return data[index.key];
                    });

                return self["index" + index.name][id];
            }
        });
    };

    HyphenDataModel.prototype.data = [];

    var clearIndexes = function () {
        var self = this;
        _(this.model.indexes).each(function (index) {
            self["index" + index.name] = null;
        });
    };

    HyphenDataModel.prototype.getData = function () {
        return _(this.data).filter(function (el) {
            return el.action != "deleted";
        })
    }

    HyphenDataModel.prototype.remove = function (data) {
        var self = this;
        var key = this.model.key;
        var data = Array.isArray(data) ? data : [data];
        _(data).each(function (record) {
            if (navigator.onLine) {
                //HyphenIndexDb.deleteRecord(self.modelName, record[key]);
                var id = (record && record[key]) ? record[key] : record;
                this.data = _(this.data).filter(function (element) {
                    return element[key] != id;
                });
            } else {
                if (record.action == "new") {
                    HyphenIndexDb.deleteRecord(self.modelName, record[key]);
                    var id = (record && record[key]) ? record[key] : record;
                    this.data = _(this.data).filter(function (element) {
                        return element[key] != id;
                    });
                }
                else {
                    record.action = "deleted";
                    HyphenIndexDb.addOrUpdateRecord(record, self.modelName, record[key]);
                    var id = (record && record[key]) ? record[key] : record;
                    this.data = _(this.data).map(function (element) {
                        if (element[key] == id) {
                            element.action = "deleted";
                        }
                        return element;
                    });
                }
            }
        }, this);

        clearIndexes.call(this);<commit_msg>-offline save upgrade<commit_after>jsHyphen.factory("HyphenDataModel", ['HyphenIndexDb', function (HyphenIndexDb) {
    var HyphenDataModel = function (model, name) {
        this.model = model;
        this.modelName = name;
        this.data = [];
        var self = this;
        _(model.indexes).each(function (index) {
            self["getBy" + index.name] = function (id) {
                if (!self["index" + index.name])
                    self["index" + index.name] = _(self.getData()).indexBy(function (data) {
                        return data[index.key];
                    });

                return self["index" + index.name][id];
            }
        });
    };

    HyphenDataModel.prototype.data = [];

    var clearIndexes = function () {
        var self = this;
        _(this.model.indexes).each(function (index) {
            self["index" + index.name] = null;
        });
    };

    HyphenDataModel.prototype.getData = function () {
        return _(this.data).filter(function (el) {
            return el.action != "deleted";
        })
    }

    HyphenDataModel.prototype.remove = function (data) {
        var self = this;
        var key = this.model.key;
        var data = Array.isArray(data) ? data : [data];
        _(data).each(function (record) {
            if (navigator.onLine) {
                //HyphenIndexDb.deleteRecord(self.modelName, record[key]);
                var id = (record && record[key]) ? record[key] : record;
                this.data = _(this.data).filter(function (element) {
                    return element[key] != id;
                });
            } else {
                if (record.action == "new") {
                    HyphenIndexDb.deleteRecord(self.modelName, record[key]);
                    /*
                     var id = (record && record[key]) ? record[key] : record;
                     this.data = _(this.data).filter(function (element) {
                     return element[key] != id;
                     });
                     */
                }
                else {
                    record.action = "deleted";
                    HyphenIndexDb.addOrUpdateRecord(record, self.modelName, record[key]);
                    /*
                     var id = (record && record[key]) ? record[key] : record;
                     this.data = _(this.data).map(function (element) {
                     if (element[key] == id) {
                     element.action = "deleted";
                     }
                     return element;
                     });
                     */
                }

                var id = (record && record[key]) ? record[key] : record;
                this.data = _(this.data).filter(function (element) {
                    return element[key] != id;
                });

            }
        }, this);

        clearIndexes.call(this);
{'fraction_non_alphanumeric': 0.13234214390602056, 'fraction_numerical': 0.0, 'mean_word_length': 1.3527633851468048, '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': '1665981', 'n_tokens_mistral': 1484, 'n_tokens_neox': 1395, 'n_words': 271}