updated binding paths (from client lib changes)
This commit is contained in:
parent
753fb27eb8
commit
f5114676e7
|
@ -59,14 +59,11 @@ const componentInstanceToBindable = walkResult => i => {
|
||||||
? getParentPath(walkResult, lastContext)
|
? 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 {
|
return {
|
||||||
type: "instance",
|
type: "instance",
|
||||||
instance: i.instance,
|
instance: i.instance,
|
||||||
// how the binding expression persists, and is used in the app at runtime
|
// 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
|
// how the binding exressions looks to the user of the builder
|
||||||
readableBinding: `${i.instance._instanceName}`,
|
readableBinding: `${i.instance._instanceName}`,
|
||||||
}
|
}
|
||||||
|
@ -79,21 +76,21 @@ const contextToBindables = walkResult => c => {
|
||||||
type: "context",
|
type: "context",
|
||||||
instance: c.instance,
|
instance: c.instance,
|
||||||
// how the binding expression persists, and is used in the app at runtime
|
// 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
|
// how the binding exressions looks to the user of the builder
|
||||||
readableBinding: `${c.instance._instanceName}.${c.model.name}.${k}`,
|
readableBinding: `${c.instance._instanceName}.${c.model.name}.${k}`,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
const getParentPath = (walkResult, context) => {
|
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
|
// clone array first so original array is not mtated
|
||||||
const contextParentNumber = [...walkResult.target._contexts]
|
const contextParentNumber = [...walkResult.target._contexts]
|
||||||
.reverse()
|
.reverse()
|
||||||
.indexOf(context)
|
.indexOf(context)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
new Array(contextParentNumber).fill("_parent").join(".") +
|
new Array(contextParentNumber).fill("parent").join(".") +
|
||||||
// trailing . if has parents
|
// trailing . if has parents
|
||||||
(contextParentNumber ? "." : "")
|
(contextParentNumber ? "." : "")
|
||||||
)
|
)
|
||||||
|
|
|
@ -9,7 +9,7 @@ describe("fetch bindable properties", () => {
|
||||||
const componentBinding = result.find(r => r.instance._id === "search-input-id" && r.type === "instance")
|
const componentBinding = result.find(r => r.instance._id === "search-input-id" && r.type === "instance")
|
||||||
expect(componentBinding).toBeDefined()
|
expect(componentBinding).toBeDefined()
|
||||||
expect(componentBinding.type).toBe("instance")
|
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", () => {
|
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")
|
const contextBindings = result.filter(r => r.instance._id === "list-id" && r.type==="context")
|
||||||
expect(contextBindings.length).toBe(2)
|
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).toBeDefined()
|
||||||
expect(namebinding.readableBinding).toBe("list-name.Test Model.name")
|
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).toBeDefined()
|
||||||
expect(descriptionbinding.readableBinding).toBe("list-name.Test Model.description")
|
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")
|
const contextBindings = result.filter(r => r.type==="context")
|
||||||
expect(contextBindings.length).toBe(4)
|
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).toBeDefined()
|
||||||
expect(namebinding_parent.readableBinding).toBe("list-name.Test Model.name")
|
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).toBeDefined()
|
||||||
expect(descriptionbinding_parent.readableBinding).toBe("list-name.Test Model.description")
|
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).toBeDefined()
|
||||||
expect(namebinding_own.readableBinding).toBe("child-list-name.Test Model.name")
|
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).toBeDefined()
|
||||||
expect(descriptionbinding_own.readableBinding).toBe("child-list-name.Test Model.description")
|
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")
|
const componentBinding = result.find(r => r.instance._id === "list-item-input-id" && r.type === "instance")
|
||||||
expect(componentBinding).toBeDefined()
|
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", () => {
|
it("should not return components from child context", () => {
|
||||||
|
|
Loading…
Reference in New Issue