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