Commit 7080c7d6 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Limit maximum number of items in History store.

Currently setting the limit to 25.

Now also keeping the store in reverse chronological order, inserting
items at the top and removing items from the bottom.
parent 62322061
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -4,6 +4,9 @@
Ext.define("Docs.History", {
    singleton: true,

    // Maximum number of items to keep in history store
    maxHistoryLength: 25,

    /**
     * Initializes history management.
     */
@@ -64,7 +67,11 @@ Ext.define("Docs.History", {
        // Add class name to history store if it's not there already
        var cls = this.parseClassName(token);
        if (cls && this.store.find('cls', cls) === -1) {
            this.store.add({cls: cls});
            this.store.insert(0, {cls: cls});
            // Remove items from the end of history if there are too many
            while (this.store.getAt(this.maxHistoryLength)) {
                this.store.removeAt(this.maxHistoryLength);
            }
            this.store.sync();
        }
    }
+5 −1
Original line number Diff line number Diff line
@@ -3,5 +3,9 @@
 */
Ext.define('Docs.store.History', {
    extend: 'Ext.data.Store',
    model: 'Docs.model.History'
    model: 'Docs.model.History',
    // Sort history with latest on top
    sorters: [
        {property: 'id', direction: 'DESC'}
    ]
});