From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 07C319171E for ; Thu, 4 Apr 2024 13:28:10 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id D8DB037A75 for ; Thu, 4 Apr 2024 13:28:09 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Thu, 4 Apr 2024 13:28:09 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id E9DDC4521A for ; Thu, 4 Apr 2024 13:28:08 +0200 (CEST) Message-ID: <6c810aab-f444-4b14-888b-ce1874f1adce@proxmox.com> Date: Thu, 4 Apr 2024 13:28:07 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: Thomas Lamprecht , Proxmox VE development discussion , Stefan Sterz References: <20240403091010.11544-1-f.weber@proxmox.com> <20240403091010.11544-4-f.weber@proxmox.com> <147ee23c-97ae-4cc5-8c1f-ffc2ad4d6773@proxmox.com> <9abfe0d9-f66d-43fe-a8df-ea36a1ad6905@proxmox.com> Content-Language: en-US From: Friedrich Weber In-Reply-To: <9abfe0d9-f66d-43fe-a8df-ea36a1ad6905@proxmox.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.073 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: Re: [pve-devel] [PATCH widget-toolkit 3/3] window: edit: avoid shared object for extra request params X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 04 Apr 2024 11:28:10 -0000 On 04/04/2024 12:59, Thomas Lamprecht wrote: > Am 04/04/2024 um 12:10 schrieb Friedrich Weber: >> Maybe we could do: >> >> ```js >> extraRequestParams: {}, >> >> constructor: function(conf) { >> let me = this; >> me.extraRequestParams = Ext.clone(me.extraRequestParams); >> me.initConfig(conf); >> me.callParent(); >> }, >> ``` >> >> ... which, if I'm not missing anything, *should* cover everything (with >> the cost of allocating unnecessary empty objects)? >> > > > yeah, I just wanted to suggest something like that, albeit I first had the > (a few times used): > > me.extraRequestParams = Ext.apply({}, me.extraRequestParams ?? {}); > > pattern in mind. Mostly an slight performance improvement as we can assume > that this is either undefined or an object, while Ext.clone checks for all > different types (in a legacy browser compat way). > > Albeit nowadays one might be even better off to use something like the > spread operator: > > me.extraRequestParams = { ...(me.extraRequestParams ?? {}) }; > > https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax#spread_in_object_literals > > Or maybe even nicer, the Object.assign operator, that does not throw if > the sources are null or undefined: > > me.extraRequestParams = Object.assign({}, me.extraRequestParams); > > https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign > > But all those are implementation details (of which I probably would prefer > the Object.assign one the most, albeit no hard feelings), in general your > proposed solution seems to be the best one, w.r.t sane new usage and > backward compat. I agree `Object.assign` looks like the nicest solution, and seeing that we already use it in our codebase, I'll go for this one. > btw. hasn't the `submitOptions` config object the same issue? You're right, `submitOptions` also has the potential for the same class of bugs. The current usages of `submitOptions` look unproblematic. But since we go for a more general fix for `extraRequestParams` anyway, let's handle `submitOptions` similarly. I'll send a v3 (just noticed I forgot the `v2` in the subject for this one). Thank you and sterzy for your suggestions!