forked from nylas/nylas-mail
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvirtual-dom-utils.es6
28 lines (27 loc) · 1000 Bytes
/
virtual-dom-utils.es6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import _ from 'underscore'
import React from 'react'
const VirtualDOMUtils = {
* walk({element, parentNode, childOffset, pruneFn = () => {}}) {
yield {element, parentNode, childOffset};
if (React.isValidElement(element) && !pruneFn(element)) {
const children = element.props.children;
if (!children) {
return
} else if (_.isString(children)) {
yield {element: children, parentNode: element, childOffset: 0}
} else if (children.length > 0) {
for (let i = 0; i < children.length; i++) {
yield* this.walk({element: children[i], parentNode: element, childOffset: i, pruneFn})
}
} else {
yield* this.walk({element: children, parentNode: element, childOffset: 0, pruneFn})
}
} else if (_.isArray(element)) {
for (let i = 0; i < element.length; i++) {
yield* this.walk({element: element[i], parentNode: element, childOffset: i})
}
}
return
},
}
export default VirtualDOMUtils