Skip to content

Commit 5c924ee

Browse files
committed
docs: use prop atom directly in counter example
Rename the seed prop to "value" and drive it via ctx.props.$value (already a WritableAtom); drop the unused atom import and nanostores importmap entry.
1 parent eab52a3 commit 5c924ee

1 file changed

Lines changed: 6 additions & 10 deletions

File tree

apps/docs/src/content/examples/counter.html

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,15 @@
77
<script type="importmap">
88
{
99
"imports": {
10-
"nanotags": "https://esm.sh/nanotags@latest",
11-
"nanostores": "https://esm.sh/nanostores@latest"
10+
"nanotags": "https://esm.sh/nanotags@latest"
1211
}
1312
}
1413
</script>
1514
</head>
1615

1716
<body>
1817
<div data-type="html">
19-
<x-counter initial="1" step="5">
18+
<x-counter value="1" step="5">
2019
<div>
2120
<input data-ref="stepInput" type="range" min="1" max="50" value="5">
2221
<span>Step: <span data-ref="step">5</span></span>
@@ -31,7 +30,6 @@
3130

3231
<script type="module" data-type="javascript">
3332
import { define } from 'nanotags';
34-
import { atom } from 'nanostores';
3533

3634
define('x-counter')
3735
.withRefs(({ one }) => ({
@@ -41,14 +39,12 @@
4139
increment: one('button'),
4240
count: one('span')
4341
}))
44-
.withProps((p) => ({ initial: p.number(), step: p.number(5) }))
42+
.withProps((p) => ({ value: p.number(), step: p.number(5) }))
4543
.setup((ctx) => {
46-
const $count = atom(ctx.props.$initial.get());
47-
4844
ctx.bind(ctx.props.$step, ctx.refs.stepInput);
49-
ctx.on(ctx.refs.increment, 'click', () => $count.set($count.get() + ctx.props.$step.get()));
50-
ctx.on(ctx.refs.decrement, 'click', () => $count.set($count.get() - ctx.props.$step.get()));
51-
ctx.effect($count, (val) => {
45+
ctx.on(ctx.refs.increment, 'click', () => ctx.props.$value.set(ctx.props.$value.get() + ctx.props.$step.get()));
46+
ctx.on(ctx.refs.decrement, 'click', () => ctx.props.$value.set(ctx.props.$value.get() - ctx.props.$step.get()));
47+
ctx.effect(ctx.props.$value, (val) => {
5248
ctx.refs.count.textContent = String(val);
5349
console.log('Count changed:', val);
5450
});

0 commit comments

Comments
 (0)