1
0
Fork 0
mirror of synced 2024-06-29 19:41:03 +12:00

Simplify reactive logic

This commit is contained in:
Andrew Kingston 2024-03-20 15:53:53 +00:00
parent 9149828c7c
commit c58ac5810e

View file

@ -28,11 +28,10 @@
$: id = $component.id $: id = $component.id
$: selected = $component.selected $: selected = $component.selected
$: inBuilder = $builderStore.inBuilder
$: builderStep = $builderStore.metadata?.step $: builderStep = $builderStore.metadata?.step
$: fetchSchema(dataSource) $: fetchSchema(dataSource)
$: enrichedSteps = enrichSteps(steps, schema, id) $: enrichedSteps = enrichSteps(steps, schema, id)
$: updateCurrentStep(enrichedSteps, selected, inBuilder, builderStep) $: updateCurrentStep(enrichedSteps, selected, builderStep)
// Provide additional data context for live binding eval // Provide additional data context for live binding eval
export const getAdditionalDataContext = () => { export const getAdditionalDataContext = () => {
@ -44,17 +43,15 @@
} }
} }
const updateCurrentStep = (steps, selected, inBuilder, builderStep) => { const updateCurrentStep = (steps, selected, builderStep) => {
// If we aren't in the builder or aren't selected then don't update the step // If we aren't selected in the builder then just allowing the normal form
// context at all, allowing the normal form to take control. // to take control.
if (!selected || !inBuilder) { if (!selected) {
return return
} }
// Ensure we have a valid step selected // Ensure we have a valid step selected
let newStep = Math.min(builderStep || 0, steps.length - 1) let newStep = Math.min(builderStep || 0, steps.length - 1)
// Sanity check
newStep = Math.max(newStep, 0) newStep = Math.max(newStep, 0)
// Add 1 because the form component expects 1 indexed rather than 0 indexed // Add 1 because the form component expects 1 indexed rather than 0 indexed