all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Friedrich Weber <f.weber@proxmox.com>
To: Thomas Lamprecht <t.lamprecht@proxmox.com>,
	Proxmox VE development discussion <pve-devel@lists.proxmox.com>,
	Stefan Sterz <s.sterz@proxmox.com>
Subject: Re: [pve-devel] [PATCH widget-toolkit 3/3] window: edit: avoid shared object for extra request params
Date: Thu, 4 Apr 2024 13:28:07 +0200	[thread overview]
Message-ID: <6c810aab-f444-4b14-888b-ce1874f1adce@proxmox.com> (raw)
In-Reply-To: <9abfe0d9-f66d-43fe-a8df-ea36a1ad6905@proxmox.com>

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!




      reply	other threads:[~2024-04-04 11:28 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-03  9:10 [pve-devel] [PATCH manager/widget-toolkit 0/3] ui: avoid UI bugs due to shared " Friedrich Weber
2024-04-03  9:10 ` [pve-devel] [PATCH manager 1/3] ui: pool members: avoid setting request parameter for all edit windows Friedrich Weber
2024-04-03  9:10 ` [pve-devel] [PATCH manager 2/3] ui: pool members: avoid sharing object for extra request parameters Friedrich Weber
2024-04-03  9:10 ` [pve-devel] [PATCH widget-toolkit 3/3] window: edit: avoid shared object for extra request params Friedrich Weber
2024-04-04  8:22   ` Stefan Sterz
2024-04-04  9:01     ` Friedrich Weber
2024-04-04  9:23       ` Stefan Sterz
2024-04-04 10:10         ` Friedrich Weber
2024-04-04 10:54           ` Stefan Sterz
2024-04-04 11:04             ` Stefan Sterz
2024-04-04 10:59           ` Thomas Lamprecht
2024-04-04 11:28             ` Friedrich Weber [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6c810aab-f444-4b14-888b-ce1874f1adce@proxmox.com \
    --to=f.weber@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    --cc=s.sterz@proxmox.com \
    --cc=t.lamprecht@proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal