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

Dominik Csapak d.csapak at proxmox.com
Thu Oct 6 09:40:01 CEST 2016


looks good to me

On 10/05/2016 11:34 AM, 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) {
>





More information about the pve-devel mailing list