Skip to content

Commit

Permalink
fix: nested if in for
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinBLT committed Jan 11, 2024
1 parent 90c004e commit d7df9ac
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/@hec.js/ui/example/component/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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) })
),
});
Expand Down
5 changes: 4 additions & 1 deletion packages/@hec.js/ui/example/list/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@
<a data-match="--active" href="../list/index.html">Current page: List</a>
<a data-match="--active" href="../inline/index.html">Inline Page</a>
<ul>
<li data-for="let color of colors" class="{{ color.class }}">{{ color.name }}</li>
<li data-for="let color of colors" class="{{ color.class }}">
<span>{{ color.name }}</span>
<span data-if="color.name"> A color!</span>
</li>
</ul>
</body>
</html>
2 changes: 0 additions & 2 deletions packages/@hec.js/ui/lib/src/plugins/data-for.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,5 @@ export const dataForPlugin = {
if (isSignal(list)) {
list.subscribe({next: update});
}

stopTemplate();
}
}
1 change: 1 addition & 0 deletions packages/@hec.js/ui/lib/src/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion packages/@hec.js/ui/lib/src/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<HTMLTemplateElement> }} */
const templatesLoading = {}
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit d7df9ac

Please sign in to comment.