[pve-devel] [PATCH widget-toolkit 2/2] data/DiffStore: auto-create the rstore if its just a config

Dominik Csapak d.csapak at proxmox.com
Thu May 7 10:27:06 CEST 2020


when rstore is not instanciated but only a config,
auto-create it with its type

this allows us to configure an diff/rstore combination completely
declaratively like this:

store: {
    type: 'diff',
    autoDestroy: true,
    autoDestroyRstore: true,
    rstore: {
	type: 'update',
	model: 'some-model',
	autoStart: true,
	interval: 5000,
    },
},

the only thing we have to be careful about is to either
do a manual 'stopUpdate' somewhere, or use the 'autoDestroyRstore' flag

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
we might want to set the 'autoDestroyRstore' automatically when
we define 'autoDestroy' and autocreated it? in that case
the chance that someone manually extracts an instance of the rstore
and uses it somewhere else is probably very low

 data/DiffStore.js | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/data/DiffStore.js b/data/DiffStore.js
index 6f335f0..2fc08be 100644
--- a/data/DiffStore.js
+++ b/data/DiffStore.js
@@ -51,7 +51,14 @@ Ext.define('Proxmox.data.DiffStore', {
 	    throw "no rstore model specified";
 	}
 
-	var rstore = config.rstore;
+	let rstore;
+	if (config.rstore.isInstance) {
+	    rstore = config.rstore;
+	} else if (config.rstore.type) {
+	    rstore = Ext.create(`store.${config.rstore.type}`, config.rstore);
+	} else {
+	    throw 'rstore is not an instance, and cannot autocreate without "type"';
+	}
 
 	Ext.apply(config, {
 	    model: rstore.model,
-- 
2.20.1





More information about the pve-devel mailing list