Skip to content

Commit

Permalink
Debounce parameter form number inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronPlave committed Nov 9, 2023
1 parent d9e41bb commit 21e10f7
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/components/parameters/ParameterBaseNumber.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<svelte:options immutable={true} />

<script lang="ts">
import { debounce } from 'lodash-es';
import { createEventDispatcher } from 'svelte';
import type { FormParameter, ParameterType } from '../../types/parameter';
import { useActions, type ActionArray } from '../../utilities/useActions';
Expand All @@ -20,7 +21,16 @@
const dispatch = createEventDispatcher();
let debouncedOnChange = debounce(onChange, 350, {
leading: true,
trailing: true,
});
$: columns = `calc(${labelColumnWidth}px - ${level * levelPadding}px) auto`;
function onChange() {
dispatch('change', formParameter);
}
</script>

<div class="parameter-base-number" style="grid-template-columns: {columns}">
Expand All @@ -33,7 +43,7 @@
{disabled}
type="number"
use:useActions={use}
on:change={() => dispatch('change', formParameter)}
on:change={debouncedOnChange}
/>
<div class="parameter-right" slot="right">
<ParameterUnits unit={formParameter.schema?.metadata?.unit?.value} />
Expand Down

0 comments on commit 21e10f7

Please sign in to comment.