[pve-devel] applied: [RFC manager] BackupEdit, cleanup: remove insideUpdate construct

Fabian Grünbichler f.gruenbichler at proxmox.com
Thu Nov 10 10:05:54 CET 2016


On Wed, Oct 05, 2016 at 11:34:17AM +0200, Thomas Lamprecht wrote:
> insideUpdate protects for a endless loop which gets caused if the sm
> selection change callback updates vmidField which then triggers the
> vmidField change callback which updates the selection model again,
> and the circle starts again.
> 
> As this construct is rather confusing when looking first at the code
> replace it with a temporary suspend of the change event during the
> vmidField update.
> 
> Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
> ---
> 
> RFC as I'm not really sorry if this gets not accepted.
> I tried to avoid the insideUpdate construct in the new HA group
> editor and found suspendEvents a quite practical solution.
> I then wanted to clean it up here too.
> 
> 
>  www/manager6/dc/Backup.js | 25 +++++++++----------------
>  1 file changed, 9 insertions(+), 16 deletions(-)
> 
> diff --git a/www/manager6/dc/Backup.js b/www/manager6/dc/Backup.js
> index 6f42ac3..b3cf36b 100644
> --- a/www/manager6/dc/Backup.js
> +++ b/www/manager6/dc/Backup.js
> @@ -35,22 +35,20 @@ Ext.define('PVE.dc.BackupEdit', {
>  	    value: ''
>  	});
>  
> -	var insideUpdate = false;
> -	
>  	var sm = Ext.create('Ext.selection.CheckboxModel', {
>  	    mode: 'SIMPLE',
>  	    listeners: {
>  		selectionchange: function(model, selected) {
> -		    if (!insideUpdate) { // avoid endless loop
> -			var sel = [];
> -			Ext.Array.each(selected, function(record) {
> -			    sel.push(record.data.vmid);
> -			});
> +		    var sel = [];
> +		    Ext.Array.each(selected, function(record) {
> +			sel.push(record.data.vmid);
> +		    });
>  
> -			insideUpdate = true;
> -			vmidField.setValue(sel);
> -			insideUpdate = false;
> -		    }
> +		    // to avoid endless recursion suspend the vmidField change
> +		    // event temporary as it calls us again
> +		    vmidField.suspendEvent('change');
> +		    vmidField.setValue(sel);
> +		    vmidField.resumeEvent('change');
>  		}
>  	    }
>  	});
> @@ -219,10 +217,6 @@ Ext.define('PVE.dc.BackupEdit', {
>  	});
>  
>  	var update_vmid_selection = function(list, mode) {
> -	    if (insideUpdate) {
> -		return; // should not happen - just to be sure
> -	    }
> -	    insideUpdate = true;
>  	    if (mode !== 'all') {
>  		sm.deselectAll(true);
>  		if (list) {
> @@ -234,7 +228,6 @@ Ext.define('PVE.dc.BackupEdit', {
>  		    });
>  		}
>  	    }
> -	    insideUpdate = false;
>  	};
>  
>  	vmidField.on('change', function(f, value) {
> -- 
> 2.1.4
> 
> 
> _______________________________________________
> pve-devel mailing list
> pve-devel at pve.proxmox.com
> http://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel




More information about the pve-devel mailing list