when this flag is set, the diffstore will automatically try to destroy
the rstore when it is destroyed itself

for this we have to move the rstore into the object (instead of using a closure)

Signed-off-by: Dominik Csapak <d.csa...@proxmox.com>
---
 data/DiffStore.js | 26 +++++++++++++++++++++-----
 1 file changed, 21 insertions(+), 5 deletions(-)

diff --git a/data/DiffStore.js b/data/DiffStore.js
index d43f111..6f335f0 100644
--- a/data/DiffStore.js
+++ b/data/DiffStore.js
@@ -24,6 +24,20 @@ Ext.define('Proxmox.data.DiffStore', {
 
     sortAfterUpdate: false,
 
+    // if set to true, destroy rstore on destruction
+    autoDestroyRstore: false,
+
+    onDestroy: function() {
+       let me = this;
+       if (me.autoDestroyRstore) {
+           if (Ext.isFunction(me.rstore.destroy)) {
+               me.rstore.destroy();
+           }
+           delete me.rstore;
+       }
+       me.callParent();
+    },
+
     constructor: function(config) {
        var me = this;
 
@@ -46,6 +60,8 @@ Ext.define('Proxmox.data.DiffStore', {
 
        me.callParent([config]);
 
+       me.rstore = rstore;
+
        var first_load = true;
 
        var cond_add_item = function(data, id) {
@@ -80,13 +96,13 @@ Ext.define('Proxmox.data.DiffStore', {
 
            // remove vanished items
            allItems.each(function(olditem) {
-               var item = rstore.getById(olditem.getId());
+               var item = me.rstore.getById(olditem.getId());
                if (!item) {
                    me.remove(olditem);
                }
            });
 
-           rstore.each(function(item) {
+           me.rstore.each(function(item) {
                cond_add_item(item.data, item.getId());
            });
 
@@ -103,12 +119,12 @@ Ext.define('Proxmox.data.DiffStore', {
            me.fireEvent('datachanged', me);
        };
 
-       if (rstore.isLoaded()) {
+       if (me.rstore.isLoaded()) {
            // if store is already loaded,
            // insert items instantly
-           loadFn(rstore, [], true);
+           loadFn(me.rstore, [], true);
        }
 
-       me.mon(rstore, 'load', loadFn);
+       me.mon(me.rstore, 'load', loadFn);
     }
 });
-- 
2.20.1


_______________________________________________
pve-devel mailing list
pve-devel@pve.proxmox.com
https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to