removed binding references to array type

This commit is contained in:
Michael Shanks 2020-01-25 05:52:59 +00:00
parent d6d936e3d0
commit b0c1ace9f0
2 changed files with 4 additions and 100 deletions

View File

@ -24,7 +24,6 @@ export const setupBinding = (store, rootProps, coreApi, context, rootPath) => {
const boundProps = []; const boundProps = [];
const contextBoundProps = []; const contextBoundProps = [];
const componentEventHandlers = []; const componentEventHandlers = [];
const boundArrays = [];
for(let propName in props) { for(let propName in props) {
@ -76,21 +75,10 @@ export const setupBinding = (store, rootProps, coreApi, context, rootPath) => {
} }
initialProps[propName] = doNothing; initialProps[propName] = doNothing;
} else if(Array.isArray(val)) { }
const arrayOfBindings = [];
for(let element of val){
arrayOfBindings.push(getBindings(element, {...element}));
}
boundArrays.push({
arrayOfBindings,
propName
});
}
} }
return {contextBoundProps, boundProps, componentEventHandlers, boundArrays, initialProps}; return {contextBoundProps, boundProps, componentEventHandlers, initialProps};
} }
@ -98,8 +86,7 @@ export const setupBinding = (store, rootProps, coreApi, context, rootPath) => {
const bind = (rootBindings) => (component) => { const bind = (rootBindings) => (component) => {
if(rootBindings.boundProps.length === 0 if(rootBindings.boundProps.length === 0
&& rootBindings.componentEventHandlers.length === 0 && rootBindings.componentEventHandlers.length === 0) return;
&& rootBindings.boundArrays.length === 0) return;
const handlerTypes = eventHandlers(store, coreApi, rootPath); const handlerTypes = eventHandlers(store, coreApi, rootPath);
@ -108,7 +95,7 @@ export const setupBinding = (store, rootProps, coreApi, context, rootPath) => {
const getPropsFromBindings = (s, bindings) => { const getPropsFromBindings = (s, bindings) => {
const {boundProps, componentEventHandlers, boundArrays} = bindings; const {boundProps, componentEventHandlers} = bindings;
const newProps = {...bindings.initialProps}; const newProps = {...bindings.initialProps};
for(let boundProp of boundProps) { for(let boundProp of boundProps) {
@ -159,18 +146,6 @@ export const setupBinding = (store, rootProps, coreApi, context, rootPath) => {
} }
for(let boundArray of boundArrays) {
let index = 0;
if(!newProps[boundArray.propName])
newProps[boundArray.propName] = [];
for(let bindings of boundArray.arrayOfBindings){
newProps[boundArray.propName][index] = getPropsFromBindings(
s,
bindings);
index++;
}
}
return newProps; return newProps;
} }
@ -189,7 +164,6 @@ export const setupBinding = (store, rootProps, coreApi, context, rootPath) => {
initialProps:rootInitialProps, initialProps:rootInitialProps,
bind:bind(bindings), bind:bind(bindings),
boundProps:bindings.boundProps, boundProps:bindings.boundProps,
boundArrays: bindings.boundArrays,
contextBoundProps: bindings.contextBoundProps contextBoundProps: bindings.contextBoundProps
}; };

View File

@ -74,59 +74,6 @@ describe("setupBinding", () => {
}); });
it("should update bound array props when updated ", () => {
const {component, store, props} = testSetup();
const {bind} = testSetupBinding(store, props, component);
bind(component);
store.update(s => {
s.FirstName = "Bobby";
s.LastName = "Thedog";
s.Customer = {
Name: "ACME inc",
Address: ""
};
s.addressToSet = "123 Main Street";
s.ArrayVal1 = "item 1 - version 1";
s.ArrayVal2 = "item 2 - version 1";
s.ArrayVal3 = "inner array item";
return s;
});
expect(component.props.arrayWithInnerBinding[0].innerBound).toBe("item 1 - version 1");
expect(component.props.arrayWithInnerBinding[1].innerBound).toBe("item 2 - version 1");
expect(component.props.arrayWithInnerBinding[0].innerUnbound).toBe("not bound 1");
expect(component.props.arrayWithInnerBinding[1].innerUnbound).toBe("not bound 2");
});
it("should update bound nested (2nd level) array props when updated ", () => {
const {component, store, props} = testSetup();
const {bind} = testSetupBinding(store, props, component);
bind(component);
store.update(s => {
s.FirstName = "Bobby";
s.LastName = "Thedog";
s.Customer = {
Name: "ACME inc",
Address: ""
};
s.addressToSet = "123 Main Street";
s.ArrayVal1 = "item 1 - version 1";
s.ArrayVal2 = "item 2 - version 1";
s.ArrayVal3 = "inner array item";
return s;
});
expect(component.props.arrayWithInnerBinding[2].innerArray[0].innerInnerBound).toBe("inner array item");
});
it("should update event handlers on state change", () => { it("should update event handlers on state change", () => {
const {component, store, props} = testSetup(); const {component, store, props} = testSetup();
@ -235,23 +182,6 @@ const testSetup = () => {
path: "Customer.Address", path: "Customer.Address",
value: binding("addressOverride", "", "event") value: binding("addressOverride", "", "event")
}) })
],
arrayWithInnerBinding: [
{
innerBound: binding("ArrayVal1"),
innerUnbound: "not bound 1"
},
{
innerBound: binding("ArrayVal2"),
innerUnbound: "not bound 2"
},
{
innerArray: [
{
innerInnerBound: binding("ArrayVal3")
}
]
}
] ]
} }