add prop iterator

This commit is contained in:
Jiiks 2018-03-08 11:17:33 +02:00
parent fdfd961390
commit 0154a7e97b
1 changed files with 15 additions and 1 deletions

View File

@ -53,6 +53,17 @@ class Reflection {
} }
return null; return null;
} }
static propIterator(obj, propNames) {
if (obj === null || obj === undefined) return null;
const curPropName = propNames.shift(1);
if (!obj.hasOwnProperty(curPropName)) return null;
const curProp = obj[curPropName];
if (propNames.length === 0) {
return curProp;
}
return this.propIterator(curProp, propNames);
}
} }
export default function (node) { export default function (node) {
@ -68,7 +79,10 @@ export default function (node) {
return Reflection.reactInternalInstance(this.node); return Reflection.reactInternalInstance(this.node);
} }
prop(propName) { prop(propName) {
return Reflection.findProp(this.node, propName); const split = propName.split('.');
const first = Reflection.findProp(this.node, split[0]);
if (split.length === 1) return first;
return Reflection.propIterator(first, split.slice(1));
} }
}(node); }(node);
} }