Skip to content

Commit 35eb661

Browse files
committed
0.1.3
1 parent 416fdca commit 35eb661

File tree

3 files changed

+38
-29
lines changed

3 files changed

+38
-29
lines changed

β€Žpackage-lock.jsonβ€Ž

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Žpackage.jsonβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@webreflection/uhtml",
3-
"version": "0.1.2",
3+
"version": "0.1.3",
44
"type": "module",
55
"scripts": {
66
"build": "npm run types && npm run build:js",

β€Žtest/base.htmlβ€Ž

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,48 @@
55
{
66
"imports": {
77
"uhtml": "../src/dom/node.js",
8-
"dom-cue": "https://esm.run/dom-cue"
8+
"dom-cue": "https://esm.run/dom-cue",
9+
"weaky": "https://esm.run/weaky"
910
}
1011
}
1112
</script>
1213
<script type="module">
13-
import { render, html, unsafe } from 'uhtml';
14-
import { effect, signal } from 'dom-cue';
14+
import { render, html, unsafe } from 'uhtml';
15+
import { effect, signal } from 'dom-cue';
16+
import { proxy, deref } from 'weaky';
1517

16-
function Button(props, state) {
17-
const counter = document.createTextNode('0');
18+
const fr = new FinalizationRegistry(cleanup => {
19+
console.log('cleaning up');
20+
cleanup();
21+
});
1822

19-
const cleanup = effect(() => {
20-
counter.data = props.signal.value;
21-
});
23+
function Button(props, state) {
24+
const counter = proxy(html`0`);
25+
const node = html`
26+
<button class="counter" onclick=${() => props.signal.value++}>
27+
${props.text}
28+
${deref(counter)}
29+
</button>
30+
`;
2231

23-
return html`
24-
<button onclick=${() => props.signal.value++}>
25-
${props.text}
26-
${counter}
27-
</button>
28-
`;
29-
}
32+
fr.register(node, effect(() => {
33+
counter.data = props.signal.value;
34+
}));
35+
36+
return node;
37+
}
3038

31-
const ref = { current: null };
32-
render(document.body, () => html`
33-
<h1 key=${1} ref=${ref} class=${'title'} onclick=${() => alert('Hello DOM!')}>
34-
Hello ${[html`DOM`]} !
35-
</h2>
36-
${unsafe('<hr />')}
37-
<${Button} text=${'πŸ‘‹'} signal=${signal(0)} />
38-
<${Button} text=${'πŸ‘‹'} signal=${signal(0)} />
39-
<${Button} text=${'πŸ‘‹'} signal=${signal(0)} />
40-
`);
39+
const ref = { current: null };
40+
render(document.body, () => html`
41+
<h1 key=${1} ref=${ref} class=${'title'} onclick=${() => alert('Hello DOM!')}>
42+
Hello ${[html`DOM`]} !
43+
</h2>
44+
${unsafe('<hr />')}
45+
<${Button} text=${'πŸ‘‹'} signal=${signal(0)} />
46+
<${Button} text=${'πŸ‘‹'} signal=${signal(0)} />
47+
<${Button} text=${'πŸ‘‹'} signal=${signal(0)} />
48+
`);
4149

42-
console.log(ref.current);
50+
console.log(ref.current);
51+
ref.current = null;
4352
</script>

0 commit comments

Comments
Β (0)