From 4fbdde2f5e1aab4479cb9208b532bbf84205e537 Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Mon, 10 Feb 2020 17:11:22 +0000 Subject: [PATCH] better state bindings for defaults --- .../src/userInterface/PropertyCascader.svelte | 47 +++++-------------- .../userInterface/StateBindingControl.svelte | 6 +-- packages/client/src/state/stateBinding.js | 1 - 3 files changed, 13 insertions(+), 41 deletions(-) diff --git a/packages/builder/src/userInterface/PropertyCascader.svelte b/packages/builder/src/userInterface/PropertyCascader.svelte index 85948c6688..c900bb2276 100644 --- a/packages/builder/src/userInterface/PropertyCascader.svelte +++ b/packages/builder/src/userInterface/PropertyCascader.svelte @@ -3,43 +3,17 @@ import { store } from "../builderStore"; import { isBinding, getBinding, setBinding } from "../common/binding"; - export let value = ""; export let onChanged = () => {}; - export let type = ""; + export let value = ""; let isOpen = false; let stateBindings = []; - let isBound = false; let bindingPath = ""; let bindingFallbackValue = ""; let bindingSource = "store"; - let isExpanded = false; - let forceIsBound = false; - let canOnlyBind = false; - $: { - canOnlyBind = type === "state"; - if (!forceIsBound && canOnlyBind) forceIsBound = true; - - isBound = forceIsBound || isBinding(value); - - if (isBound) { - const binding = getBinding(value); - bindingPath = binding.path; - bindingFallbackValue = binding.fallback; - bindingSource = binding.source || "store"; - } else { - bindingPath = ""; - bindingFallbackValue = ""; - bindingSource = "store"; - } - } - - const clearBinding = () => { - forceIsBound = false; - onChanged(""); - }; + const clearBinding = () => onChanged(""); const bind = (path, fallback, source) => { if (!path) { @@ -50,10 +24,8 @@ onChanged(binding); }; - const setBindingPath = value => { - forceIsBound = canOnlyBind; + const setBindingPath = value => bind(value, bindingFallbackValue, bindingSource); - }; const setBindingFallback = value => bind(bindingPath, value, bindingSource); @@ -61,10 +33,15 @@ bind(bindingPath, bindingFallbackValue, value); $: { + + const binding = getBinding(value); + bindingPath = binding.path + bindingFallbackValue = binding.fallback + console.log({ bindingFallbackValue, bindingPath, - value + value, }); const currentScreen = $store.screens.find( @@ -79,9 +56,9 @@ { - setBindingFallback(e.target.value) - }}/> + on:change={e => { + setBindingFallback(e.target.value); + }} />