@@ -9,6 +9,20 @@ import {CounterStore, counterStore} from '../../stores/counterStore';
99
1010const batchStore = createClassyStore ( new CounterStore ( ) ) ;
1111
12+ class DemoFormStore {
13+ name = 'Alice' ;
14+
15+ setName ( value : string ) {
16+ this . name = value ;
17+ }
18+
19+ reset ( ) {
20+ this . name = 'Alice' ;
21+ }
22+ }
23+
24+ const formStore = createClassyStore ( new DemoFormStore ( ) ) ;
25+
1226const names = [ 'World' , 'Bun' , 'React' , 'Store' ] ;
1327let nameIndex = 0 ;
1428
@@ -44,6 +58,17 @@ function BatchCard() {
4458 // 1000 mutations → 1 render (microtask batching)
4559 const count = useClassyStore(batchStore, (state) => state.count);
4660 return <div>{count}</div>;
61+ }
62+
63+ function NameInput() {
64+ const name = useClassyStore(formStore, (state) => state.name, { sync: true });
65+
66+ return (
67+ <input
68+ value={name}
69+ onChange={(event) => formStore.setName(event.target.value)}
70+ />
71+ );
4772}` ;
4873
4974function CountCard ( ) {
@@ -100,13 +125,34 @@ function BatchCard() {
100125 ) ;
101126}
102127
128+ function NameInputCard ( ) {
129+ const name = useClassyStore ( formStore , ( state ) => state . name , { sync : true } ) ;
130+ const renders = useRenderCount ( ) ;
131+
132+ return (
133+ < div className = "flex-1 flex items-center justify-between gap-3 bg-emerald-500/10 border border-emerald-500/20 rounded-lg px-3 py-2.5" >
134+ < label className = "flex-1 min-w-0" >
135+ < span className = "block text-[10px] text-zinc-400 uppercase tracking-wide mb-1" >
136+ Name Input
137+ </ span >
138+ < input
139+ value = { name }
140+ onChange = { ( event ) => formStore . setName ( event . target . value ) }
141+ className = "w-full rounded-md border border-zinc-700 bg-zinc-900 px-2 py-1.5 text-sm text-zinc-100 outline-none focus:border-emerald-400"
142+ />
143+ </ label >
144+ < RenderBadge count = { renders } />
145+ </ div >
146+ ) ;
147+ }
148+
103149export function ReactiveFundamentalsDemo ( ) {
104150 const [ lastBatch , setLastBatch ] = useState ( false ) ;
105151
106152 return (
107153 < DemoContainer
108154 title = "Reactive Fundamentals"
109- description = "Render isolation via selectors + microtask batching + mutable deep updates — all in one store."
155+ description = "Render isolation via selectors + controlled inputs + microtask batching + mutable deep updates — all in one store."
110156 codeTabs = { [
111157 { label : 'Store' , code : STORE_CODE , language : 'typescript' } ,
112158 { label : 'Component' , code : COMPONENT_CODE } ,
@@ -115,6 +161,7 @@ export function ReactiveFundamentalsDemo() {
115161 < div className = "flex flex-col gap-3 mb-4" >
116162 < CountCard />
117163 < NameCard />
164+ < NameInputCard />
118165 < BatchCard />
119166 </ div >
120167
@@ -144,6 +191,7 @@ export function ReactiveFundamentalsDemo() {
144191 onClick = { ( ) => {
145192 counterStore . reset ( ) ;
146193 batchStore . reset ( ) ;
194+ formStore . reset ( ) ;
147195 setLastBatch ( false ) ;
148196 } }
149197 >
0 commit comments