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