Skip to content

Instantly share code, notes, and snippets.

@Noitidart
Created August 18, 2017 23:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Noitidart/6623ad8cef68e68b011d2c030299ecf9 to your computer and use it in GitHub Desktop.
Save Noitidart/6623ad8cef68e68b011d2c030299ecf9 to your computer and use it in GitHub Desktop.
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