<commit_before>Rpd.history = (function() {

    var limit = 50;

    function History() {
        this.reset();
    }

    History.prototype.reset = function() {
        this.stack = [];
    }

    History.prototype.undo = function() {

    }

    History.prototype.redo = function() {

    }

    History.prototype.getRecordCount = function() {
        return this.stack.length;
    }

    return new History();

})();<commit_msg>thoughts on implementing History (#278)<commit_after>Rpd.history = (function() {

    var limit = 50;

    var undoRedoMap = {
        'network/add-patch': function(update, stack) {
            return { type: 'network/remove-patch',
                     patch: update.patch };
        }
    };

    function History() {
        this.reset();
        Rpd.events.filter(function(update) {
            return undoRedoMap[update.type];
        }).onValue(function(update) {
            if (this.stack.length > limit) {
                this.stack.shift();
            }
            this.stack.push(update);
        }.bind(this));
    }

    History.prototype.reset = function() {
        this.stack = [];
        this.position = 0;
    }

    History.prototype.undo = function() {
        if (this.position === 0) return;
        var lastAction = this.stack.pop();
        var reversedAction = undoRedoMap[lastAction.type](lastAction, this.stack);
        Rpd.events[reversedAction.type].emit(reversedAction);
    }

    History.prototype.redo = function() {
        if (this.position === 0) return;
        var lastAction = this.stack.pop();
        Rpd.events[lastAction.type].emit(lastAction);
    }

    History.prototype.getRecordCount = function() {
        return this.stack.length;
    }

    return new History();

})();
{'fraction_non_alphanumeric': 0.1413105413105413, 'fraction_numerical': 0.005698005698005698, 'mean_word_length': 2.048611111111111, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '4373276', 'n_tokens_mistral': 538, 'n_tokens_neox': 499, 'n_words': 90}