From e896904af160d760b235e9ac175f7ffe1d959d02 Mon Sep 17 00:00:00 2001 From: Dean Date: Wed, 10 Jan 2024 17:12:02 +0000 Subject: [PATCH] Added value caching to alleviate too many updates when hovering --- .../controls/FormStepConfiguration.svelte | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/packages/builder/src/components/design/settings/controls/FormStepConfiguration.svelte b/packages/builder/src/components/design/settings/controls/FormStepConfiguration.svelte index bd28347e08..2941821dec 100644 --- a/packages/builder/src/components/design/settings/controls/FormStepConfiguration.svelte +++ b/packages/builder/src/components/design/settings/controls/FormStepConfiguration.svelte @@ -6,7 +6,7 @@ import { Helpers } from "@budibase/bbui" import { derived, writable } from "svelte/store" import { Utils } from "@budibase/frontend-core" - import { cloneDeep } from "lodash" + import { cloneDeep, isEqual } from "lodash" export let componentInstance export let componentBindings @@ -21,21 +21,32 @@ const currentStep = derived(multiStepStore, state => state.currentStep) const componentType = "@budibase/standard-components/multistepformblockstep" + let cachedValue + let cachedInstance = {} + + $: if (!isEqual(cachedValue, value)) { + cachedValue = value + } + + $: if (!isEqual(componentInstance, cachedInstance)) { + cachedInstance = componentInstance + } + setContext("multi-step-form-block", multiStepStore) - $: stepCount = value?.length || 0 + $: stepCount = cachedValue?.length || 0 $: updateStore(stepCount) - $: dataSource = getDatasourceForProvider($currentAsset, componentInstance) + $: dataSource = getDatasourceForProvider($currentAsset, cachedInstance) $: emitCurrentStep($currentStep) $: stepLabel = getStepLabel($multiStepStore) $: stepDef = getDefinition(stepLabel) - $: stepSettings = value?.[$currentStep] || {} + $: stepSettings = cachedValue?.[$currentStep] || {} $: defaults = Utils.buildMultiStepFormBlockDefaultProps({ - _id: componentInstance._id, + _id: cachedInstance._id, stepCount: $multiStepStore.stepCount, currentStep: $multiStepStore.currentStep, - actionType: componentInstance.actionType, - dataSource: componentInstance.dataSource, + actionType: cachedInstance.actionType, + dataSource: cachedInstance.dataSource, }) $: stepInstance = { _id: Helpers.uuid(),