You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: improve Storybook story code display and fix demo issues
- Add custom source code (parameters.docs.source.code) to all stories
so the code panel shows meaningful example code instead of internal
render wrappers
- Fix controlEqual + memo demo: use explicit value in setNum to avoid
stale closure, add parent render count and "Re-render Parent" button
to clearly demonstrate memo behavior
- Fix Double transform description: mapSetter(v => v * 2) doubles the
written value, not simply "adds 2"
@@ -199,6 +246,39 @@ export const WithControlEqual: Story = {
199
246
description: {
200
247
story: '`controlEqual` lets `React.memo` compare control props by their state values, avoiding unnecessary re-renders when the control reference changes but the value stays the same.',
<button onClick={() => setTick(t => t + 1)}>Re-render Parent</button>
275
+
<MemoCounter count={controlA} />
276
+
<MemoCounter count={controlB} />
277
+
</div>
278
+
);
279
+
}`,
280
+
language: 'tsx',
281
+
},
202
282
},
203
283
},
204
284
};
@@ -211,6 +291,49 @@ export const CrossLayer: Story = {
211
291
description: {
212
292
story: 'A single `control` flows through multiple layers of wrapper components (App → Panel → Card → Input). Every component at any depth can read and write the same state — no Context provider, no callback prop drilling.',
213
293
},
294
+
source: {
295
+
code: `function TemperatureInput({ temperature }) {
@@ -168,7 +169,20 @@ export const Double: Story = {
168
169
parameters: {
169
170
docs: {
170
171
description: {
171
-
story: '`mapSetter` transforms the value before it reaches setState — every increment is doubled.',
172
+
story: '`mapSetter` transforms the value before it reaches setState — the written value is doubled. E.g. `setState(n => n + 1)` with state `0` computes `1`, then `mapSetter` turns it into `1 * 2 = 2`.',
173
+
},
174
+
source: {
175
+
code: `function DoubleCounter() {
176
+
const [, , control] = useControl(0);
177
+
const doubled = useThru(control, mapSetter(v => v * 2));
178
+
return <SimpleCounter count={doubled} />;
179
+
}
180
+
181
+
// Child calls setState(n => n + 1):
182
+
// state 0 → (0+1) → mapSetter → 1*2 = 2
183
+
// state 2 → (2+1) → mapSetter → 3*2 = 6
184
+
// state 6 → (6+1) → mapSetter → 7*2 = 14`,
185
+
language: 'tsx',
172
186
},
173
187
},
174
188
},
@@ -181,6 +195,17 @@ export const Clamped: Story = {
181
195
description: {
182
196
story: '`mapSetter` with a clamp function to restrict the value range.',
183
197
},
198
+
source: {
199
+
code: `function ClampedCounter() {
200
+
const [, , control] = useControl(5);
201
+
const clamped = useThru(
202
+
control,
203
+
mapSetter(v => Math.max(0, Math.min(10, v)))
204
+
);
205
+
return <ClampedDisplay count={clamped} />;
206
+
}`,
207
+
language: 'tsx',
208
+
},
184
209
},
185
210
},
186
211
};
@@ -193,6 +218,21 @@ export const MapState: Story = {
193
218
description: {
194
219
story: '`mapState` transforms the value that children see, without affecting the stored value.',
195
220
},
221
+
source: {
222
+
code: `function MapStateDemo() {
223
+
const [, , control] = useControl(0);
224
+
// Child sees value * 100, but stored value is unchanged
225
+
const scaled = useThru(control, mapState(v => v * 100));
0 commit comments