From 8a070ff278067fc4cd3c008e1dcbb7744f4e4497 Mon Sep 17 00:00:00 2001 From: Karsten Schmidt Date: Tue, 27 Feb 2018 14:34:18 +0000 Subject: [PATCH] feat(hiccup-dom): start(), add optional spans arg --- packages/hiccup-dom/src/start.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/hiccup-dom/src/start.ts b/packages/hiccup-dom/src/start.ts index c4a0ddbfe8..c40b92526a 100644 --- a/packages/hiccup-dom/src/start.ts +++ b/packages/hiccup-dom/src/start.ts @@ -1,5 +1,6 @@ import { isString } from "@thi.ng/checks/is-string"; -import { diffElement, normalizeTree } from "./diff"; +import { diffElement } from "./diff"; +import { normalizeTree } from "./normalize"; /** * Takes a parent DOM element (or ID) and hiccup tree @@ -10,15 +11,17 @@ import { diffElement, normalizeTree } from "./diff"; * Important: The parent element given is assumed to have NO * children at the time when `start()` is called. Since * hiccup-dom does NOT track the real DOM, the resulting - * changes will result in potentially undefined behavior. + * changes will result in potentially undefined behavior + * if the parent element wasn't empty. * * Returns a function, which when called, immediately * cancels the update loop. * - * @param parent - * @param tree + * @param parent root element or ID + * @param tree hiccup DOM tree + * @param spans true (default), if text should be wrapped in `` */ -export function start(parent: Element | string, tree: any) { +export function start(parent: Element | string, tree: any, spans = true) { let prev = []; let isActive = true; parent = isString(parent) ? @@ -26,7 +29,7 @@ export function start(parent: Element | string, tree: any) { parent; function update() { if (isActive) { - diffElement(parent, prev, prev = normalizeTree(tree)); + diffElement(parent, prev, prev = normalizeTree(tree, [0], true, spans)); // check again in case one of the components called cancel isActive && requestAnimationFrame(update); }