-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f680f3b
commit 9f2fda3
Showing
5 changed files
with
213 additions
and
76 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { getDomSibling } from '../component'; | ||
import { isArray } from '../util'; | ||
|
||
/** | ||
* @param {VNode} parentVNode | ||
* @param {PreactElement} oldDom | ||
* @param {PreactElement} parentDom | ||
* @returns {PreactElement} | ||
*/ | ||
export function insert(parentVNode, oldDom, parentDom) { | ||
// Note: VNodes in nested suspended trees may be missing _children. | ||
|
||
if (typeof parentVNode.type == 'function') { | ||
let children = parentVNode._children; | ||
for (let i = 0; children && i < children.length; i++) { | ||
if (children[i]) { | ||
// If we enter this code path on sCU bailout, where we copy | ||
// oldVNode._children to newVNode._children, we need to update the old | ||
// children's _parent pointer to point to the newVNode (parentVNode | ||
// here). | ||
children[i]._parent = parentVNode; | ||
oldDom = insert(children[i], oldDom, parentDom); | ||
} | ||
} | ||
|
||
return oldDom; | ||
} else if (parentVNode._dom != oldDom) { | ||
if (oldDom && parentVNode.type && !parentDom.contains(oldDom)) { | ||
oldDom = getDomSibling(parentVNode); | ||
} | ||
parentDom.insertBefore(parentVNode._dom, oldDom || null); | ||
oldDom = parentVNode._dom; | ||
} | ||
|
||
do { | ||
oldDom = oldDom && oldDom.nextSibling; | ||
} while (oldDom != null && oldDom.nodeType === 8); | ||
|
||
return oldDom; | ||
} | ||
|
||
/** | ||
* Flatten and loop through the children of a virtual node | ||
* @param {ComponentChildren} children The unflattened children of a virtual | ||
* node | ||
* @returns {VNode[]} | ||
*/ | ||
export function toChildArray(children, out) { | ||
out = out || []; | ||
if (children == null || typeof children == 'boolean') { | ||
} else if (isArray(children)) { | ||
children.some(child => { | ||
toChildArray(child, out); | ||
}); | ||
} else { | ||
out.push(children); | ||
} | ||
return out; | ||
} |
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
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