Transmit actual Nodes across Syndicate bus, rather than HTML string
This commit is contained in:
parent
b0fe7baf25
commit
b5a4a150ac
|
@ -129,7 +129,7 @@ function spawnUIFragmentFactory<T>(thisFacet: Facet<T>) {
|
||||||
assert P.UIFragmentVersion(fragmentId, this.version) when (this.version > 0);
|
assert P.UIFragmentVersion(fragmentId, this.version) when (this.version > 0);
|
||||||
|
|
||||||
let selector: string;
|
let selector: string;
|
||||||
let html: string;
|
let html: Array<ChildNode>;
|
||||||
let orderBy: NodeOrderKey;
|
let orderBy: NodeOrderKey;
|
||||||
let anchorNodes: Array<Element> = [];
|
let anchorNodes: Array<Element> = [];
|
||||||
let eventRegistrations =
|
let eventRegistrations =
|
||||||
|
@ -142,13 +142,13 @@ function spawnUIFragmentFactory<T>(thisFacet: Facet<T>) {
|
||||||
on stop updateEventListeners([ selector, eventType ], false);
|
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;
|
if (!isNodeOrderKey(newOrderBy)) return;
|
||||||
|
|
||||||
removeNodes();
|
removeNodes();
|
||||||
|
|
||||||
selector = newSelector;
|
selector = newSelector;
|
||||||
html = newHtml;
|
html = newHtml as Array<ChildNode>;
|
||||||
orderBy = newOrderBy;
|
orderBy = newOrderBy;
|
||||||
anchorNodes = (selector !== null) ? selectorMatch(document.body, selector) : [];
|
anchorNodes = (selector !== null) ? selectorMatch(document.body, selector) : [];
|
||||||
|
|
||||||
|
@ -158,7 +158,7 @@ function spawnUIFragmentFactory<T>(thisFacet: Facet<T>) {
|
||||||
|
|
||||||
anchorNodes.forEach(anchorNode => {
|
anchorNodes.forEach(anchorNode => {
|
||||||
let insertionPoint = findInsertionPoint(anchorNode, orderBy, fragmentId);
|
let insertionPoint = findInsertionPoint(anchorNode, orderBy, fragmentId);
|
||||||
htmlToNodes(anchorNode, html).forEach(newNode => {
|
html.forEach(newNode => {
|
||||||
setSortKey(newNode, orderBy, fragmentId);
|
setSortKey(newNode, orderBy, fragmentId);
|
||||||
anchorNode.insertBefore(newNode, insertionPoint);
|
anchorNode.insertBefore(newNode, insertionPoint);
|
||||||
configureNode(newNode);
|
configureNode(newNode);
|
||||||
|
@ -307,12 +307,6 @@ function findInsertionPoint(n: Node, orderBy: NodeOrderKey, fragmentId: Fragment
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function htmlToNodes(parent: Element, html: string): Array<ChildNode> {
|
|
||||||
let e = parent.cloneNode(false) as Element;
|
|
||||||
e.innerHTML = html;
|
|
||||||
return Array.from(e.childNodes);
|
|
||||||
}
|
|
||||||
|
|
||||||
function configureNode(n: ChildNode) {
|
function configureNode(n: ChildNode) {
|
||||||
// Runs post-insertion configuration of nodes.
|
// Runs post-insertion configuration of nodes.
|
||||||
// TODO: review this design.
|
// TODO: review this design.
|
||||||
|
@ -486,11 +480,8 @@ export class Anchor {
|
||||||
return new Anchor({ fragmentId: this.fragmentId + '__' + extn });
|
return new Anchor({ fragmentId: this.fragmentId + '__' + extn });
|
||||||
}
|
}
|
||||||
|
|
||||||
html(selector: string, html: HtmlFragments | string, orderBy: NodeOrderKey = ''): Record {
|
html(selector: string, html: HtmlFragments, orderBy: NodeOrderKey = ''): Record {
|
||||||
return P.UIFragment(this.fragmentId,
|
return P.UIFragment(this.fragmentId, selector, html.nodes(), orderBy);
|
||||||
selector,
|
|
||||||
typeof html === 'string' ? html : html.toString(),
|
|
||||||
orderBy);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue