From d7df9acd741e2886234200c918b01ae88869873a Mon Sep 17 00:00:00 2001 From: Kevin Bulteel Date: Thu, 11 Jan 2024 13:10:51 +0100 Subject: [PATCH] fix: nested if in for --- packages/@hec.js/ui/example/component/index.html | 2 +- packages/@hec.js/ui/example/list/index.html | 5 ++++- packages/@hec.js/ui/lib/src/plugins/data-for.js | 2 -- packages/@hec.js/ui/lib/src/props.js | 1 + packages/@hec.js/ui/lib/src/template.js | 6 +++++- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/@hec.js/ui/example/component/index.html b/packages/@hec.js/ui/example/component/index.html index f6a1f7c..5692991 100644 --- a/packages/@hec.js/ui/example/component/index.html +++ b/packages/@hec.js/ui/example/component/index.html @@ -14,7 +14,7 @@ import { templateByNode } from '../../lib/index.js'; templateByNode(document.body, { - list: Array.from({ length: 1 || Math.round(Math.random() * 100)}, () => ( + list: Array.from({ length: Math.round(Math.random() * 100)}, () => ( { count: Math.round(Math.random() * 0xffffff) }) ), }); diff --git a/packages/@hec.js/ui/example/list/index.html b/packages/@hec.js/ui/example/list/index.html index 21cf9e0..e52505c 100644 --- a/packages/@hec.js/ui/example/list/index.html +++ b/packages/@hec.js/ui/example/list/index.html @@ -30,7 +30,10 @@ Current page: List Inline Page diff --git a/packages/@hec.js/ui/lib/src/plugins/data-for.js b/packages/@hec.js/ui/lib/src/plugins/data-for.js index 102afe4..7af55c1 100644 --- a/packages/@hec.js/ui/lib/src/plugins/data-for.js +++ b/packages/@hec.js/ui/lib/src/plugins/data-for.js @@ -59,7 +59,5 @@ export const dataForPlugin = { if (isSignal(list)) { list.subscribe({next: update}); } - - stopTemplate(); } } \ No newline at end of file diff --git a/packages/@hec.js/ui/lib/src/props.js b/packages/@hec.js/ui/lib/src/props.js index 8c7f75c..0cabfff 100644 --- a/packages/@hec.js/ui/lib/src/props.js +++ b/packages/@hec.js/ui/lib/src/props.js @@ -9,6 +9,7 @@ const nodeProps = new WeakMap(); /** @param { Node } node */ export const propsOf = (node) => nodeProps.get(node); export const deletePropsOf = (node) => nodeProps.delete(node); +export const hasProps = (node) => nodeProps.has(node); export const setPropsOf = (node, props) => { const existing = propsOf(node); diff --git a/packages/@hec.js/ui/lib/src/template.js b/packages/@hec.js/ui/lib/src/template.js index 8954ea4..afaa7d9 100644 --- a/packages/@hec.js/ui/lib/src/template.js +++ b/packages/@hec.js/ui/lib/src/template.js @@ -2,7 +2,7 @@ import { expression } from './expression.js'; import { pipes } from './pipes.js'; import { plugins } from './plugins.js'; import { isSignal } from './signal.js'; -import { f, setPropsOf, prop, hasProp } from './props.js'; +import { f, setPropsOf, prop, hasProp, hasProps } from './props.js'; /** @type {{ [key: string]: Promise }} */ const templatesLoading = {} @@ -137,6 +137,10 @@ export function templateByNode(template, props = {}) { const findExpression = (node) => { let stopFlag = false; + if (hasProps(node)) { + return; + } + if (node.nodeName == '#document-fragment') { setPropsOf(node, props); }