rob-balfre / svelte-select

Svelte Select. A select component for Svelte
https://svelte-select-examples.vercel.app
Other
1.25k stars 175 forks source link

Do not assign to `null` if it is `undefined` #531

Closed frederikhors closed 1 year ago

frederikhors commented 1 year ago

Using the same code of https://github.com/rob-balfre/svelte-select/issues/529 in a different REPL (https://svelte.dev/repl/22b8f93585ee4771893a565bbbb7ff47?version=3.55.1) you can see how svelte-select re-assign value when is undefined but not when it is null (see the console).

I expect to not get re-assigned when is undefined either.

This may seem negligible, but when there are 30+ components on a page it is not at all (performances).

I think this is not correct even from a formal point of view: "If my value is undefined why do you change it to null?".

<script>
  import Select from "./Select.svelte";

  //let team = {id: "1", name: "The selectors", player: {id: "5", firstname: "Rob"}};

  // This gets re-assigned (to null)
  let team = {id: "1", name: "The selectors", player: undefined};

  // This don't (because already null obviously)
  //let team = {id: "1", name: "The selectors", player: null};

  $: console.log("team re-assigned:", team);
</script>

team: {JSON.stringify(team)}
<br><br>

<Select
  bind:value={team.player}
>
</Select>
rob-balfre commented 1 year ago

See #529