From f5114676e7d3e0faf8ca43314f00b4d5e6d0da73 Mon Sep 17 00:00:00 2001 From: Michael Shanks Date: Thu, 6 Aug 2020 21:27:26 +0100 Subject: [PATCH] updated binding paths (from client lib changes) --- .../src/builderStore/fetchBindableProperties.js | 11 ++++------- packages/builder/tests/binding.spec.js | 16 ++++++++-------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/packages/builder/src/builderStore/fetchBindableProperties.js b/packages/builder/src/builderStore/fetchBindableProperties.js index d2d775ccad..93407fb941 100644 --- a/packages/builder/src/builderStore/fetchBindableProperties.js +++ b/packages/builder/src/builderStore/fetchBindableProperties.js @@ -59,14 +59,11 @@ const componentInstanceToBindable = walkResult => i => { ? getParentPath(walkResult, lastContext) : "" - // if component is inside context, then the component lives - // in context at runtime (otherwise, in state) - const stateOrContext = lastContext ? "context" : "state" return { type: "instance", instance: i.instance, // how the binding expression persists, and is used in the app at runtime - runtimeBinding: `${stateOrContext}.${contextParentPath}${i.instance._id}.${i.prop}`, + runtimeBinding: `${contextParentPath}${i.instance._id}.${i.prop}`, // how the binding exressions looks to the user of the builder readableBinding: `${i.instance._instanceName}`, } @@ -79,21 +76,21 @@ const contextToBindables = walkResult => c => { type: "context", instance: c.instance, // how the binding expression persists, and is used in the app at runtime - runtimeBinding: `context.${contextParentPath}data.${k}`, + runtimeBinding: `${contextParentPath}data.${k}`, // how the binding exressions looks to the user of the builder readableBinding: `${c.instance._instanceName}.${c.model.name}.${k}`, })) } const getParentPath = (walkResult, context) => { - // describes the number of "_parent" in the path + // describes the number of "parent" in the path // clone array first so original array is not mtated const contextParentNumber = [...walkResult.target._contexts] .reverse() .indexOf(context) return ( - new Array(contextParentNumber).fill("_parent").join(".") + + new Array(contextParentNumber).fill("parent").join(".") + // trailing . if has parents (contextParentNumber ? "." : "") ) diff --git a/packages/builder/tests/binding.spec.js b/packages/builder/tests/binding.spec.js index ac90faf9bf..c8372b0255 100644 --- a/packages/builder/tests/binding.spec.js +++ b/packages/builder/tests/binding.spec.js @@ -9,7 +9,7 @@ describe("fetch bindable properties", () => { const componentBinding = result.find(r => r.instance._id === "search-input-id" && r.type === "instance") expect(componentBinding).toBeDefined() expect(componentBinding.type).toBe("instance") - expect(componentBinding.runtimeBinding).toBe("state.search-input-id.value") + expect(componentBinding.runtimeBinding).toBe("search-input-id.value") }) it("should not return bindable components when not in their context", () => { @@ -29,11 +29,11 @@ describe("fetch bindable properties", () => { const contextBindings = result.filter(r => r.instance._id === "list-id" && r.type==="context") expect(contextBindings.length).toBe(2) - const namebinding = contextBindings.find(b => b.runtimeBinding === "context.data.name") + const namebinding = contextBindings.find(b => b.runtimeBinding === "data.name") expect(namebinding).toBeDefined() expect(namebinding.readableBinding).toBe("list-name.Test Model.name") - const descriptionbinding = contextBindings.find(b => b.runtimeBinding === "context.data.description") + const descriptionbinding = contextBindings.find(b => b.runtimeBinding === "data.description") expect(descriptionbinding).toBeDefined() expect(descriptionbinding.readableBinding).toBe("list-name.Test Model.description") }) @@ -46,19 +46,19 @@ describe("fetch bindable properties", () => { const contextBindings = result.filter(r => r.type==="context") expect(contextBindings.length).toBe(4) - const namebinding_parent = contextBindings.find(b => b.runtimeBinding === "context._parent.data.name") + const namebinding_parent = contextBindings.find(b => b.runtimeBinding === "parent.data.name") expect(namebinding_parent).toBeDefined() expect(namebinding_parent.readableBinding).toBe("list-name.Test Model.name") - const descriptionbinding_parent = contextBindings.find(b => b.runtimeBinding === "context._parent.data.description") + const descriptionbinding_parent = contextBindings.find(b => b.runtimeBinding === "parent.data.description") expect(descriptionbinding_parent).toBeDefined() expect(descriptionbinding_parent.readableBinding).toBe("list-name.Test Model.description") - const namebinding_own = contextBindings.find(b => b.runtimeBinding === "context.data.name") + const namebinding_own = contextBindings.find(b => b.runtimeBinding === "data.name") expect(namebinding_own).toBeDefined() expect(namebinding_own.readableBinding).toBe("child-list-name.Test Model.name") - const descriptionbinding_own = contextBindings.find(b => b.runtimeBinding === "context.data.description") + const descriptionbinding_own = contextBindings.find(b => b.runtimeBinding === "data.description") expect(descriptionbinding_own).toBeDefined() expect(descriptionbinding_own.readableBinding).toBe("child-list-name.Test Model.description") }) @@ -70,7 +70,7 @@ describe("fetch bindable properties", () => { }) const componentBinding = result.find(r => r.instance._id === "list-item-input-id" && r.type === "instance") expect(componentBinding).toBeDefined() - expect(componentBinding.runtimeBinding).toBe("context.list-item-input-id.value") + expect(componentBinding.runtimeBinding).toBe("list-item-input-id.value") }) it("should not return components from child context", () => {