MCPcopy
hub / github.com/preactjs/preact / createRootFragment

Function createRootFragment

test/ts/preact.tsx:102–120  ·  view source on GitHub ↗
(parent: Element, replaceNode: Element | Element[])

Source from the content-addressed store, hash-verified

100
101// From https://gist.github.com/developit/f4c67a2ede71dc2fab7f357f39cff28c, modified to be TypeScript compliant
102function createRootFragment(parent: Element, replaceNode: Element | Element[]) {
103 const replaceNodes: Element[] = ([] as Element[]).concat(replaceNode);
104 const s = replaceNodes[replaceNodes.length - 1].nextSibling;
105 function insert(c: Node, r: Node | null) {
106 return parent.insertBefore(c, r || s);
107 }
108 return ((parent as any).__k = {
109 nodeType: 1,
110 parentNode: parent,
111 firstChild: replaceNodes[0],
112 childNodes: replaceNodes,
113 contains: (c: Node) => parent.contains(c),
114 insertBefore: insert,
115 appendChild: (c: Node) => insert(c, null),
116 removeChild: function (c: Node) {
117 return parent.removeChild(c);
118 }
119 });
120}
121
122render(
123 h('div', {}),

Callers 1

preact.tsxFile · 0.85

Calls 3

insertFunction · 0.70
containsMethod · 0.65
removeChildMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…