diff --git a/packages/html/src/index.ts b/packages/html/src/index.ts index 6ce895d..86b9b56 100644 --- a/packages/html/src/index.ts +++ b/packages/html/src/index.ts @@ -129,7 +129,7 @@ function spawnUIFragmentFactory(thisFacet: Facet) { assert P.UIFragmentVersion(fragmentId, this.version) when (this.version > 0); let selector: string; - let html: string; + let html: Array; let orderBy: NodeOrderKey; let anchorNodes: Array = []; let eventRegistrations = @@ -142,13 +142,13 @@ function spawnUIFragmentFactory(thisFacet: Facet) { on stop updateEventListeners([ selector, eventType ], false); } - on asserted P.UIFragment(fragmentId, $newSelector: string, $newHtml: string, $newOrderBy) => { + on asserted P.UIFragment(fragmentId, $newSelector: string, $newHtml, $newOrderBy) => { if (!isNodeOrderKey(newOrderBy)) return; removeNodes(); selector = newSelector; - html = newHtml; + html = newHtml as Array; orderBy = newOrderBy; anchorNodes = (selector !== null) ? selectorMatch(document.body, selector) : []; @@ -158,7 +158,7 @@ function spawnUIFragmentFactory(thisFacet: Facet) { anchorNodes.forEach(anchorNode => { let insertionPoint = findInsertionPoint(anchorNode, orderBy, fragmentId); - htmlToNodes(anchorNode, html).forEach(newNode => { + html.forEach(newNode => { setSortKey(newNode, orderBy, fragmentId); anchorNode.insertBefore(newNode, insertionPoint); configureNode(newNode); @@ -307,12 +307,6 @@ function findInsertionPoint(n: Node, orderBy: NodeOrderKey, fragmentId: Fragment } } -function htmlToNodes(parent: Element, html: string): Array { - let e = parent.cloneNode(false) as Element; - e.innerHTML = html; - return Array.from(e.childNodes); -} - function configureNode(n: ChildNode) { // Runs post-insertion configuration of nodes. // TODO: review this design. @@ -486,11 +480,8 @@ export class Anchor { return new Anchor({ fragmentId: this.fragmentId + '__' + extn }); } - html(selector: string, html: HtmlFragments | string, orderBy: NodeOrderKey = ''): Record { - return P.UIFragment(this.fragmentId, - selector, - typeof html === 'string' ? html : html.toString(), - orderBy); + html(selector: string, html: HtmlFragments, orderBy: NodeOrderKey = ''): Record { + return P.UIFragment(this.fragmentId, selector, html.nodes(), orderBy); } }