|
7 | 7 | <script type="importmap"> |
8 | 8 | { |
9 | 9 | "imports": { |
10 | | - "nanotags": "https://esm.sh/nanotags@latest", |
11 | | - "nanostores": "https://esm.sh/nanostores@latest" |
| 10 | + "nanotags": "https://esm.sh/nanotags@latest" |
12 | 11 | } |
13 | 12 | } |
14 | 13 | </script> |
15 | 14 | </head> |
16 | 15 |
|
17 | 16 | <body> |
18 | 17 | <div data-type="html"> |
19 | | - <x-counter initial="1" step="5"> |
| 18 | + <x-counter value="1" step="5"> |
20 | 19 | <div> |
21 | 20 | <input data-ref="stepInput" type="range" min="1" max="50" value="5"> |
22 | 21 | <span>Step: <span data-ref="step">5</span></span> |
|
31 | 30 |
|
32 | 31 | <script type="module" data-type="javascript"> |
33 | 32 | import { define } from 'nanotags'; |
34 | | - import { atom } from 'nanostores'; |
35 | 33 |
|
36 | 34 | define('x-counter') |
37 | 35 | .withRefs(({ one }) => ({ |
|
41 | 39 | increment: one('button'), |
42 | 40 | count: one('span') |
43 | 41 | })) |
44 | | - .withProps((p) => ({ initial: p.number(), step: p.number(5) })) |
| 42 | + .withProps((p) => ({ value: p.number(), step: p.number(5) })) |
45 | 43 | .setup((ctx) => { |
46 | | - const $count = atom(ctx.props.$initial.get()); |
47 | | - |
48 | 44 | 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) => { |
52 | 48 | ctx.refs.count.textContent = String(val); |
53 | 49 | console.log('Count changed:', val); |
54 | 50 | }); |
|
0 commit comments