Created
August 18, 2017 23:11
-
-
Save Noitidart/6623ad8cef68e68b011d2c030299ecf9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
render() { | |
const view = super.render() | |
// if (elementsTree && elementsTree.type === 'input') { | |
// newProps = {value: 'may the force be with you'} | |
// } | |
// depth first - stack - last in first out | |
// iterate depth first until a Field is found | |
const fields = []; | |
const elements = [view]; // stack | |
console.log('view:', view); | |
while (elements.length) { | |
const element = elements.pop(); | |
const primative = typeof element; | |
// if (primative !== 'object') { | |
// // string, number etc | |
// fields.push(primative); | |
// } else { | |
// fields.push(element.type + ` (${typeof element.type}) (isField:${element.type === Field})`); | |
// } | |
if (primative === 'object') { | |
if (element.type === Field) { | |
fields.push(element); | |
} else { | |
if (element.props) { | |
const children = element.props.children; | |
if (children) { | |
if (Array.isArray(children)) { | |
elements.push(...children); | |
} else { | |
elements.push(children); | |
} | |
} | |
} else { | |
console.log('no props on element:', element); | |
} | |
} | |
} else { | |
console.log('is primative so no props:', element); | |
} | |
} | |
console.log('fields:', fields); | |
// const props = Object.assign({}, elementsTree.props, newProps); | |
const viewNew = React.cloneElement(view, view.props, view.props.children); | |
return viewNew; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment