@mandujs/mcp 0.36.2 → 0.37.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -4
- package/src/activity-adapter.ts +23 -23
- package/src/adapters/index.ts +20 -20
- package/src/adapters/monitor-adapter.ts +100 -100
- package/src/adapters/tool-adapter.ts +90 -90
- package/src/executor/index.ts +22 -22
- package/src/executor/tool-executor.ts +148 -148
- package/src/hooks/config-watcher.ts +173 -173
- package/src/hooks/index.ts +23 -23
- package/src/hooks/mcp-hooks.ts +227 -227
- package/src/index.ts +0 -0
- package/src/logging/index.ts +15 -15
- package/src/logging/mcp-transport.ts +134 -134
- package/src/profiles.ts +34 -34
- package/src/registry/index.ts +13 -13
- package/src/registry/mcp-tool-registry.ts +298 -298
- package/src/resources/skills/guides.ts +1136 -1136
- package/src/resources/skills/index.ts +12 -12
- package/src/resources/skills/mandu-composition/SKILL.md +91 -91
- package/src/resources/skills/mandu-composition/metadata.json +13 -13
- package/src/resources/skills/mandu-composition/rules/_sections.md +26 -26
- package/src/resources/skills/mandu-composition/rules/_template.md +77 -77
- package/src/resources/skills/mandu-composition/rules/comp-arch-avoid-boolean-props.md +146 -146
- package/src/resources/skills/mandu-composition/rules/comp-arch-compound-components.md +164 -164
- package/src/resources/skills/mandu-composition/rules/comp-island-event.md +161 -161
- package/src/resources/skills/mandu-composition/rules/comp-island-slot-split.md +167 -167
- package/src/resources/skills/mandu-composition/rules/comp-pattern-children.md +149 -149
- package/src/resources/skills/mandu-composition/rules/comp-state-context-interface.md +148 -148
- package/src/resources/skills/mandu-composition/rules/comp-state-lift-state.md +150 -150
- package/src/resources/skills/mandu-deployment/SKILL.md +92 -92
- package/src/resources/skills/mandu-deployment/_sections.md +41 -41
- package/src/resources/skills/mandu-deployment/_template.md +38 -38
- package/src/resources/skills/mandu-deployment/metadata.json +13 -13
- package/src/resources/skills/mandu-deployment/rules/db-provider-supabase.md +300 -300
- package/src/resources/skills/mandu-deployment/rules/deploy-build-bun.md +109 -109
- package/src/resources/skills/mandu-deployment/rules/deploy-build-output.md +115 -115
- package/src/resources/skills/mandu-deployment/rules/deploy-cicd-github.md +219 -219
- package/src/resources/skills/mandu-deployment/rules/deploy-docker-bun.md +150 -150
- package/src/resources/skills/mandu-deployment/rules/deploy-docker-compose.md +223 -223
- package/src/resources/skills/mandu-deployment/rules/deploy-platform-fly.md +152 -152
- package/src/resources/skills/mandu-deployment/rules/deploy-platform-render.md +179 -179
- package/src/resources/skills/mandu-deployment/rules/deploy-platform-vercel.md +140 -140
- package/src/resources/skills/mandu-fs-routes/SKILL.md +82 -82
- package/src/resources/skills/mandu-fs-routes/metadata.json +12 -12
- package/src/resources/skills/mandu-fs-routes/rules/_sections.md +36 -36
- package/src/resources/skills/mandu-fs-routes/rules/_template.md +69 -69
- package/src/resources/skills/mandu-fs-routes/rules/routes-api-methods.md +65 -65
- package/src/resources/skills/mandu-fs-routes/rules/routes-dynamic-param.md +93 -93
- package/src/resources/skills/mandu-fs-routes/rules/routes-naming-page.md +55 -55
- package/src/resources/skills/mandu-guard/SKILL.md +129 -129
- package/src/resources/skills/mandu-guard/metadata.json +12 -12
- package/src/resources/skills/mandu-guard/rules/_sections.md +36 -36
- package/src/resources/skills/mandu-guard/rules/_template.md +82 -82
- package/src/resources/skills/mandu-guard/rules/guard-config-rules.md +100 -100
- package/src/resources/skills/mandu-guard/rules/guard-layer-direction.md +76 -76
- package/src/resources/skills/mandu-guard/rules/guard-preset-mandu.md +81 -81
- package/src/resources/skills/mandu-guard/rules/guard-validate-import.md +80 -80
- package/src/resources/skills/mandu-hydration/SKILL.md +91 -91
- package/src/resources/skills/mandu-hydration/metadata.json +12 -12
- package/src/resources/skills/mandu-hydration/rules/_sections.md +31 -31
- package/src/resources/skills/mandu-hydration/rules/_template.md +72 -72
- package/src/resources/skills/mandu-hydration/rules/hydration-data-event.md +109 -109
- package/src/resources/skills/mandu-hydration/rules/hydration-directive-use-client.md +55 -55
- package/src/resources/skills/mandu-hydration/rules/hydration-island-setup.md +113 -113
- package/src/resources/skills/mandu-hydration/rules/hydration-priority-visible.md +68 -68
- package/src/resources/skills/mandu-performance/SKILL.md +85 -85
- package/src/resources/skills/mandu-performance/metadata.json +14 -14
- package/src/resources/skills/mandu-performance/rules/_sections.md +31 -31
- package/src/resources/skills/mandu-performance/rules/_template.md +64 -64
- package/src/resources/skills/mandu-performance/rules/perf-async-defer-await.md +103 -103
- package/src/resources/skills/mandu-performance/rules/perf-async-parallel.md +95 -95
- package/src/resources/skills/mandu-performance/rules/perf-bun-file.md +124 -124
- package/src/resources/skills/mandu-performance/rules/perf-bun-serve.md +125 -125
- package/src/resources/skills/mandu-performance/rules/perf-bundle-imports.md +80 -80
- package/src/resources/skills/mandu-performance/rules/perf-bundle-island-lazy.md +145 -145
- package/src/resources/skills/mandu-performance/rules/perf-cache-react.md +98 -98
- package/src/resources/skills/mandu-performance/rules/perf-render-transitions.md +154 -154
- package/src/resources/skills/mandu-security/SKILL.md +87 -87
- package/src/resources/skills/mandu-security/metadata.json +13 -13
- package/src/resources/skills/mandu-security/rules/_sections.md +31 -31
- package/src/resources/skills/mandu-security/rules/_template.md +74 -74
- package/src/resources/skills/mandu-security/rules/sec-auth-guard.md +127 -127
- package/src/resources/skills/mandu-security/rules/sec-env-management.md +133 -133
- package/src/resources/skills/mandu-security/rules/sec-input-validate.md +148 -148
- package/src/resources/skills/mandu-security/rules/sec-protect-csrf.md +146 -146
- package/src/resources/skills/mandu-security/rules/sec-protect-headers.md +138 -138
- package/src/resources/skills/mandu-slot/SKILL.md +85 -85
- package/src/resources/skills/mandu-slot/metadata.json +12 -12
- package/src/resources/skills/mandu-slot/rules/_sections.md +36 -36
- package/src/resources/skills/mandu-slot/rules/_template.md +63 -63
- package/src/resources/skills/mandu-slot/rules/slot-basic-structure.md +38 -38
- package/src/resources/skills/mandu-slot/rules/slot-ctx-response.md +56 -56
- package/src/resources/skills/mandu-slot/rules/slot-guard-auth.md +59 -59
- package/src/resources/skills/mandu-slot/rules/slot-http-methods.md +64 -64
- package/src/resources/skills/mandu-styling/SKILL.md +154 -154
- package/src/resources/skills/mandu-styling/_sections.md +43 -43
- package/src/resources/skills/mandu-styling/_template.md +32 -32
- package/src/resources/skills/mandu-styling/metadata.json +15 -15
- package/src/resources/skills/mandu-styling/rules/style-component-compound.md +235 -235
- package/src/resources/skills/mandu-styling/rules/style-component-slots.md +255 -255
- package/src/resources/skills/mandu-styling/rules/style-component-tokens.md +205 -205
- package/src/resources/skills/mandu-styling/rules/style-island-animations.md +272 -272
- package/src/resources/skills/mandu-styling/rules/style-island-scoping.md +167 -167
- package/src/resources/skills/mandu-styling/rules/style-island-variants.md +221 -221
- package/src/resources/skills/mandu-styling/rules/style-perf-critical.md +209 -209
- package/src/resources/skills/mandu-styling/rules/style-perf-purge.md +192 -192
- package/src/resources/skills/mandu-styling/rules/style-setup-modules.md +162 -162
- package/src/resources/skills/mandu-styling/rules/style-setup-panda.md +164 -164
- package/src/resources/skills/mandu-styling/rules/style-setup-tailwind.md +170 -170
- package/src/resources/skills/mandu-styling/rules/style-tailwind-v4-gotchas.md +179 -179
- package/src/resources/skills/mandu-styling/rules/style-theme-darkmode.md +229 -229
- package/src/resources/skills/mandu-testing/SKILL.md +99 -99
- package/src/resources/skills/mandu-testing/metadata.json +13 -13
- package/src/resources/skills/mandu-testing/rules/_sections.md +26 -26
- package/src/resources/skills/mandu-testing/rules/_template.md +65 -65
- package/src/resources/skills/mandu-testing/rules/test-component-island.md +195 -195
- package/src/resources/skills/mandu-testing/rules/test-e2e-playwright.md +196 -196
- package/src/resources/skills/mandu-testing/rules/test-mock-fetch.md +219 -219
- package/src/resources/skills/mandu-testing/rules/test-slot-unit.md +192 -192
- package/src/resources/skills/mandu-ui/SKILL.md +117 -117
- package/src/resources/skills/mandu-ui/_sections.md +23 -23
- package/src/resources/skills/mandu-ui/_template.md +32 -32
- package/src/resources/skills/mandu-ui/metadata.json +13 -13
- package/src/resources/skills/mandu-ui/rules/ui-accessibility-aria.md +232 -232
- package/src/resources/skills/mandu-ui/rules/ui-accessibility-focus.md +238 -238
- package/src/resources/skills/mandu-ui/rules/ui-composition-patterns.md +259 -259
- package/src/resources/skills/mandu-ui/rules/ui-island-integration.md +258 -258
- package/src/resources/skills/mandu-ui/rules/ui-radix-patterns.md +213 -213
- package/src/resources/skills/mandu-ui/rules/ui-shadcn-setup.md +209 -209
- package/src/resources/skills/recipes.ts +932 -932
- package/src/server.ts +3 -3
- package/src/tools/ate-exemplar.ts +92 -92
- package/src/tools/ate-flakes.ts +90 -90
- package/src/tools/ate-mutate.ts +103 -103
- package/src/tools/ate-mutation-report.ts +64 -64
- package/src/tools/ate-oracle-pending.ts +49 -49
- package/src/tools/ate-oracle-replay.ts +44 -44
- package/src/tools/ate-oracle-verdict.ts +70 -70
- package/src/tools/ate-prompt.ts +146 -146
- package/src/tools/brain.ts +3 -3
- package/src/tools/deploy-plan.ts +378 -378
- package/src/tools/deploy-preview.ts +316 -316
- package/src/tools/design.ts +825 -825
- package/src/tools/docs.ts +350 -350
- package/src/tools/kitchen.ts +109 -23
- package/src/tools/lint.ts +226 -226
- package/src/tools/loop-close.ts +175 -175
- package/src/tools/negotiate.ts +263 -263
- package/src/tools/run-tests.ts +424 -424
- package/src/tools/runtime.ts +1 -1
- package/src/tools/slot-validation.ts +199 -199
- package/src/tx-lock.ts +73 -73
- package/src/utils/runtime-control.ts +52 -52
|
@@ -1,149 +1,149 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: Use Children for Composition Over Render Props
|
|
3
|
-
impact: MEDIUM
|
|
4
|
-
impactDescription: Simpler API, better composition
|
|
5
|
-
tags: composition, children, render-props, pattern
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
## Use Children for Composition Over Render Props
|
|
9
|
-
|
|
10
|
-
**Impact: MEDIUM (Simpler API, better composition)**
|
|
11
|
-
|
|
12
|
-
`renderX` props 대신 `children`을 사용하여 컴포지션하세요. 더 선언적이고 유연합니다.
|
|
13
|
-
|
|
14
|
-
**Incorrect (render props):**
|
|
15
|
-
|
|
16
|
-
```tsx
|
|
17
|
-
// ❌ renderX props 패턴
|
|
18
|
-
function Modal({
|
|
19
|
-
renderHeader,
|
|
20
|
-
renderBody,
|
|
21
|
-
renderFooter,
|
|
22
|
-
renderCloseButton,
|
|
23
|
-
}: ModalProps) {
|
|
24
|
-
return (
|
|
25
|
-
<div className="modal">
|
|
26
|
-
<div className="modal-header">
|
|
27
|
-
{renderCloseButton?.()}
|
|
28
|
-
{renderHeader?.()}
|
|
29
|
-
</div>
|
|
30
|
-
<div className="modal-body">
|
|
31
|
-
{renderBody?.()}
|
|
32
|
-
</div>
|
|
33
|
-
<div className="modal-footer">
|
|
34
|
-
{renderFooter?.()}
|
|
35
|
-
</div>
|
|
36
|
-
</div>
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// 사용 시 복잡함
|
|
41
|
-
<Modal
|
|
42
|
-
renderHeader={() => <h2>Title</h2>}
|
|
43
|
-
renderBody={() => <p>Content</p>}
|
|
44
|
-
renderFooter={() => (
|
|
45
|
-
<>
|
|
46
|
-
<Button>Cancel</Button>
|
|
47
|
-
<Button>Save</Button>
|
|
48
|
-
</>
|
|
49
|
-
)}
|
|
50
|
-
renderCloseButton={() => <CloseButton />}
|
|
51
|
-
/>
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
**Correct (children + compound):**
|
|
55
|
-
|
|
56
|
-
```tsx
|
|
57
|
-
// ✅ children과 컴파운드 패턴
|
|
58
|
-
function Modal({ children }: { children: React.ReactNode }) {
|
|
59
|
-
return <div className="modal">{children}</div>;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function ModalHeader({ children }: { children: React.ReactNode }) {
|
|
63
|
-
return <div className="modal-header">{children}</div>;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function ModalBody({ children }: { children: React.ReactNode }) {
|
|
67
|
-
return <div className="modal-body">{children}</div>;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function ModalFooter({ children }: { children: React.ReactNode }) {
|
|
71
|
-
return <div className="modal-footer">{children}</div>;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function ModalClose({ onClose }: { onClose: () => void }) {
|
|
75
|
-
return <button onClick={onClose} className="modal-close">×</button>;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export { Modal, ModalHeader, ModalBody, ModalFooter, ModalClose };
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
**사용:**
|
|
82
|
-
|
|
83
|
-
```tsx
|
|
84
|
-
// 선언적이고 명확함
|
|
85
|
-
<Modal>
|
|
86
|
-
<ModalHeader>
|
|
87
|
-
<ModalClose onClose={handleClose} />
|
|
88
|
-
<h2>Title</h2>
|
|
89
|
-
</ModalHeader>
|
|
90
|
-
|
|
91
|
-
<ModalBody>
|
|
92
|
-
<p>Content goes here</p>
|
|
93
|
-
</ModalBody>
|
|
94
|
-
|
|
95
|
-
<ModalFooter>
|
|
96
|
-
<Button onClick={handleClose}>Cancel</Button>
|
|
97
|
-
<Button onClick={handleSave}>Save</Button>
|
|
98
|
-
</ModalFooter>
|
|
99
|
-
</Modal>
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
## 장점
|
|
103
|
-
|
|
104
|
-
| render props | children |
|
|
105
|
-
|--------------|----------|
|
|
106
|
-
| 숨겨진 구조 | 명시적 구조 |
|
|
107
|
-
| 함수 호출 문법 | JSX 문법 |
|
|
108
|
-
| 순서가 props에 의존 | 순서를 소비자가 제어 |
|
|
109
|
-
| 어떤 props가 있는지 봐야 함 | 자동완성 지원 |
|
|
110
|
-
|
|
111
|
-
## Mandu Island에서의 적용
|
|
112
|
-
|
|
113
|
-
```tsx
|
|
114
|
-
// ❌ 피해야 할 패턴
|
|
115
|
-
<FormIsland
|
|
116
|
-
renderInput={(value, onChange) => <Input value={value} onChange={onChange} />}
|
|
117
|
-
renderSubmit={(onSubmit) => <Button onClick={onSubmit}>Submit</Button>}
|
|
118
|
-
renderError={(error) => <ErrorMessage error={error} />}
|
|
119
|
-
/>
|
|
120
|
-
|
|
121
|
-
// ✅ 권장 패턴
|
|
122
|
-
<Form.Provider>
|
|
123
|
-
<Form.Frame>
|
|
124
|
-
<Form.Input name="email" />
|
|
125
|
-
<Form.Input name="password" type="password" />
|
|
126
|
-
<Form.Error />
|
|
127
|
-
<Form.Submit>Sign In</Form.Submit>
|
|
128
|
-
</Form.Frame>
|
|
129
|
-
</Form.Provider>
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
## 언제 Render Props를 사용하나?
|
|
133
|
-
|
|
134
|
-
render props가 여전히 유용한 경우:
|
|
135
|
-
- 부모가 데이터를 제공하고 자식이 렌더링 방법을 결정 (예: virtualized list)
|
|
136
|
-
- 자식에게 상태를 노출해야 하는 headless 컴포넌트
|
|
137
|
-
|
|
138
|
-
```tsx
|
|
139
|
-
// Render props가 적합한 예: Virtualized List
|
|
140
|
-
<VirtualList
|
|
141
|
-
items={items}
|
|
142
|
-
itemHeight={50}
|
|
143
|
-
renderItem={(item, index) => (
|
|
144
|
-
<div key={item.id}>{item.name}</div>
|
|
145
|
-
)}
|
|
146
|
-
/>
|
|
147
|
-
```
|
|
148
|
-
|
|
149
|
-
Reference: [Compound Components](https://kentcdodds.com/blog/compound-components-with-react-hooks)
|
|
1
|
+
---
|
|
2
|
+
title: Use Children for Composition Over Render Props
|
|
3
|
+
impact: MEDIUM
|
|
4
|
+
impactDescription: Simpler API, better composition
|
|
5
|
+
tags: composition, children, render-props, pattern
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Use Children for Composition Over Render Props
|
|
9
|
+
|
|
10
|
+
**Impact: MEDIUM (Simpler API, better composition)**
|
|
11
|
+
|
|
12
|
+
`renderX` props 대신 `children`을 사용하여 컴포지션하세요. 더 선언적이고 유연합니다.
|
|
13
|
+
|
|
14
|
+
**Incorrect (render props):**
|
|
15
|
+
|
|
16
|
+
```tsx
|
|
17
|
+
// ❌ renderX props 패턴
|
|
18
|
+
function Modal({
|
|
19
|
+
renderHeader,
|
|
20
|
+
renderBody,
|
|
21
|
+
renderFooter,
|
|
22
|
+
renderCloseButton,
|
|
23
|
+
}: ModalProps) {
|
|
24
|
+
return (
|
|
25
|
+
<div className="modal">
|
|
26
|
+
<div className="modal-header">
|
|
27
|
+
{renderCloseButton?.()}
|
|
28
|
+
{renderHeader?.()}
|
|
29
|
+
</div>
|
|
30
|
+
<div className="modal-body">
|
|
31
|
+
{renderBody?.()}
|
|
32
|
+
</div>
|
|
33
|
+
<div className="modal-footer">
|
|
34
|
+
{renderFooter?.()}
|
|
35
|
+
</div>
|
|
36
|
+
</div>
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// 사용 시 복잡함
|
|
41
|
+
<Modal
|
|
42
|
+
renderHeader={() => <h2>Title</h2>}
|
|
43
|
+
renderBody={() => <p>Content</p>}
|
|
44
|
+
renderFooter={() => (
|
|
45
|
+
<>
|
|
46
|
+
<Button>Cancel</Button>
|
|
47
|
+
<Button>Save</Button>
|
|
48
|
+
</>
|
|
49
|
+
)}
|
|
50
|
+
renderCloseButton={() => <CloseButton />}
|
|
51
|
+
/>
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
**Correct (children + compound):**
|
|
55
|
+
|
|
56
|
+
```tsx
|
|
57
|
+
// ✅ children과 컴파운드 패턴
|
|
58
|
+
function Modal({ children }: { children: React.ReactNode }) {
|
|
59
|
+
return <div className="modal">{children}</div>;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function ModalHeader({ children }: { children: React.ReactNode }) {
|
|
63
|
+
return <div className="modal-header">{children}</div>;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function ModalBody({ children }: { children: React.ReactNode }) {
|
|
67
|
+
return <div className="modal-body">{children}</div>;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function ModalFooter({ children }: { children: React.ReactNode }) {
|
|
71
|
+
return <div className="modal-footer">{children}</div>;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function ModalClose({ onClose }: { onClose: () => void }) {
|
|
75
|
+
return <button onClick={onClose} className="modal-close">×</button>;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export { Modal, ModalHeader, ModalBody, ModalFooter, ModalClose };
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
**사용:**
|
|
82
|
+
|
|
83
|
+
```tsx
|
|
84
|
+
// 선언적이고 명확함
|
|
85
|
+
<Modal>
|
|
86
|
+
<ModalHeader>
|
|
87
|
+
<ModalClose onClose={handleClose} />
|
|
88
|
+
<h2>Title</h2>
|
|
89
|
+
</ModalHeader>
|
|
90
|
+
|
|
91
|
+
<ModalBody>
|
|
92
|
+
<p>Content goes here</p>
|
|
93
|
+
</ModalBody>
|
|
94
|
+
|
|
95
|
+
<ModalFooter>
|
|
96
|
+
<Button onClick={handleClose}>Cancel</Button>
|
|
97
|
+
<Button onClick={handleSave}>Save</Button>
|
|
98
|
+
</ModalFooter>
|
|
99
|
+
</Modal>
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## 장점
|
|
103
|
+
|
|
104
|
+
| render props | children |
|
|
105
|
+
|--------------|----------|
|
|
106
|
+
| 숨겨진 구조 | 명시적 구조 |
|
|
107
|
+
| 함수 호출 문법 | JSX 문법 |
|
|
108
|
+
| 순서가 props에 의존 | 순서를 소비자가 제어 |
|
|
109
|
+
| 어떤 props가 있는지 봐야 함 | 자동완성 지원 |
|
|
110
|
+
|
|
111
|
+
## Mandu Island에서의 적용
|
|
112
|
+
|
|
113
|
+
```tsx
|
|
114
|
+
// ❌ 피해야 할 패턴
|
|
115
|
+
<FormIsland
|
|
116
|
+
renderInput={(value, onChange) => <Input value={value} onChange={onChange} />}
|
|
117
|
+
renderSubmit={(onSubmit) => <Button onClick={onSubmit}>Submit</Button>}
|
|
118
|
+
renderError={(error) => <ErrorMessage error={error} />}
|
|
119
|
+
/>
|
|
120
|
+
|
|
121
|
+
// ✅ 권장 패턴
|
|
122
|
+
<Form.Provider>
|
|
123
|
+
<Form.Frame>
|
|
124
|
+
<Form.Input name="email" />
|
|
125
|
+
<Form.Input name="password" type="password" />
|
|
126
|
+
<Form.Error />
|
|
127
|
+
<Form.Submit>Sign In</Form.Submit>
|
|
128
|
+
</Form.Frame>
|
|
129
|
+
</Form.Provider>
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## 언제 Render Props를 사용하나?
|
|
133
|
+
|
|
134
|
+
render props가 여전히 유용한 경우:
|
|
135
|
+
- 부모가 데이터를 제공하고 자식이 렌더링 방법을 결정 (예: virtualized list)
|
|
136
|
+
- 자식에게 상태를 노출해야 하는 headless 컴포넌트
|
|
137
|
+
|
|
138
|
+
```tsx
|
|
139
|
+
// Render props가 적합한 예: Virtualized List
|
|
140
|
+
<VirtualList
|
|
141
|
+
items={items}
|
|
142
|
+
itemHeight={50}
|
|
143
|
+
renderItem={(item, index) => (
|
|
144
|
+
<div key={item.id}>{item.name}</div>
|
|
145
|
+
)}
|
|
146
|
+
/>
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
Reference: [Compound Components](https://kentcdodds.com/blog/compound-components-with-react-hooks)
|
|
@@ -1,148 +1,148 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: Define Generic Context Interface for Dependency Injection
|
|
3
|
-
impact: HIGH
|
|
4
|
-
impactDescription: Enables dependency-injectable state across use-cases
|
|
5
|
-
tags: composition, context, state, typescript, dependency-injection
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
## Define Generic Context Interface for Dependency Injection
|
|
9
|
-
|
|
10
|
-
**Impact: HIGH (Enables dependency-injectable state across use-cases)**
|
|
11
|
-
|
|
12
|
-
컴포넌트 context를 위한 제네릭 인터페이스를 `state`, `actions`, `meta` 세 부분으로 정의하세요. 어떤 Provider든 이 인터페이스를 구현할 수 있어, 같은 UI 컴포넌트가 완전히 다른 상태 구현과 작동할 수 있습니다.
|
|
13
|
-
|
|
14
|
-
**핵심 원칙:** Lift state, compose internals, make state dependency-injectable.
|
|
15
|
-
|
|
16
|
-
**Incorrect (특정 상태 구현에 결합):**
|
|
17
|
-
|
|
18
|
-
```tsx
|
|
19
|
-
// ❌ 특정 훅에 강하게 결합
|
|
20
|
-
function ComposerInput() {
|
|
21
|
-
const { input, setInput } = useChannelComposerState();
|
|
22
|
-
return <TextInput value={input} onChangeText={setInput} />;
|
|
23
|
-
}
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
**Correct (제네릭 인터페이스로 의존성 주입):**
|
|
27
|
-
|
|
28
|
-
```tsx
|
|
29
|
-
// ✅ 어떤 Provider든 구현할 수 있는 제네릭 인터페이스
|
|
30
|
-
interface ComposerState {
|
|
31
|
-
input: string;
|
|
32
|
-
attachments: Attachment[];
|
|
33
|
-
isSubmitting: boolean;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
interface ComposerActions {
|
|
37
|
-
update: (updater: (state: ComposerState) => ComposerState) => void;
|
|
38
|
-
submit: () => void;
|
|
39
|
-
addAttachment: (file: File) => void;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
interface ComposerMeta {
|
|
43
|
-
inputRef: React.RefObject<HTMLTextAreaElement>;
|
|
44
|
-
maxLength?: number;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
interface ComposerContextValue {
|
|
48
|
-
state: ComposerState;
|
|
49
|
-
actions: ComposerActions;
|
|
50
|
-
meta: ComposerMeta;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const ComposerContext = createContext<ComposerContextValue | null>(null);
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
**UI 컴포넌트는 인터페이스만 소비:**
|
|
57
|
-
|
|
58
|
-
```tsx
|
|
59
|
-
function ComposerInput() {
|
|
60
|
-
const {
|
|
61
|
-
state,
|
|
62
|
-
actions: { update },
|
|
63
|
-
meta,
|
|
64
|
-
} = use(ComposerContext)!;
|
|
65
|
-
|
|
66
|
-
// 이 컴포넌트는 인터페이스를 구현한 어떤 Provider와도 작동
|
|
67
|
-
return (
|
|
68
|
-
<textarea
|
|
69
|
-
ref={meta.inputRef}
|
|
70
|
-
value={state.input}
|
|
71
|
-
maxLength={meta.maxLength}
|
|
72
|
-
onChange={(e) => update((s) => ({ ...s, input: e.target.value }))}
|
|
73
|
-
/>
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
**서로 다른 Provider가 같은 인터페이스 구현:**
|
|
79
|
-
|
|
80
|
-
```tsx
|
|
81
|
-
// Provider A: 임시 폼을 위한 로컬 상태
|
|
82
|
-
function ForwardMessageProvider({ children }: { children: React.ReactNode }) {
|
|
83
|
-
const [state, setState] = useState(initialState);
|
|
84
|
-
const inputRef = useRef<HTMLTextAreaElement>(null);
|
|
85
|
-
const submit = useForwardMessage();
|
|
86
|
-
|
|
87
|
-
return (
|
|
88
|
-
<ComposerContext value={{
|
|
89
|
-
state,
|
|
90
|
-
actions: { update: setState, submit, addAttachment: ... },
|
|
91
|
-
meta: { inputRef },
|
|
92
|
-
}}>
|
|
93
|
-
{children}
|
|
94
|
-
</ComposerContext>
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// Provider B: 채널을 위한 전역 동기화 상태
|
|
99
|
-
function ChannelProvider({ channelId, children }: Props) {
|
|
100
|
-
const { state, update, submit } = useGlobalChannel(channelId);
|
|
101
|
-
const inputRef = useRef<HTMLTextAreaElement>(null);
|
|
102
|
-
|
|
103
|
-
return (
|
|
104
|
-
<ComposerContext value={{
|
|
105
|
-
state,
|
|
106
|
-
actions: { update, submit, addAttachment: ... },
|
|
107
|
-
meta: { inputRef, maxLength: 2000 },
|
|
108
|
-
}}>
|
|
109
|
-
{children}
|
|
110
|
-
</ComposerContext>
|
|
111
|
-
);
|
|
112
|
-
}
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
**같은 UI가 두 Provider와 모두 작동:**
|
|
116
|
-
|
|
117
|
-
```tsx
|
|
118
|
-
// ForwardMessageProvider와 작동 (로컬 상태)
|
|
119
|
-
<ForwardMessageProvider>
|
|
120
|
-
<Composer.Frame>
|
|
121
|
-
<Composer.Input />
|
|
122
|
-
<Composer.Submit />
|
|
123
|
-
</Composer.Frame>
|
|
124
|
-
</ForwardMessageProvider>
|
|
125
|
-
|
|
126
|
-
// ChannelProvider와 작동 (전역 동기화 상태)
|
|
127
|
-
<ChannelProvider channelId="abc">
|
|
128
|
-
<Composer.Frame>
|
|
129
|
-
<Composer.Input />
|
|
130
|
-
<Composer.Submit />
|
|
131
|
-
</Composer.Frame>
|
|
132
|
-
</ChannelProvider>
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
## Mandu Island에서의 활용
|
|
136
|
-
|
|
137
|
-
```tsx
|
|
138
|
-
// Island 컴포넌트는 인터페이스만 알면 됨
|
|
139
|
-
// slot에서 어떤 Provider를 사용하든 같은 Island 재사용 가능
|
|
140
|
-
|
|
141
|
-
// spec/slots/forward.slot.ts → ForwardMessageProvider 사용
|
|
142
|
-
// spec/slots/channel.slot.ts → ChannelProvider 사용
|
|
143
|
-
// 둘 다 같은 Composer Island 컴포넌트 사용
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
UI는 재사용 가능한 조각들이고, 상태는 Provider가 주입합니다. Provider를 바꾸면 UI는 그대로!
|
|
147
|
-
|
|
148
|
-
Reference: [Context Interface Pattern](https://kentcdodds.com/blog/how-to-use-react-context-effectively)
|
|
1
|
+
---
|
|
2
|
+
title: Define Generic Context Interface for Dependency Injection
|
|
3
|
+
impact: HIGH
|
|
4
|
+
impactDescription: Enables dependency-injectable state across use-cases
|
|
5
|
+
tags: composition, context, state, typescript, dependency-injection
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Define Generic Context Interface for Dependency Injection
|
|
9
|
+
|
|
10
|
+
**Impact: HIGH (Enables dependency-injectable state across use-cases)**
|
|
11
|
+
|
|
12
|
+
컴포넌트 context를 위한 제네릭 인터페이스를 `state`, `actions`, `meta` 세 부분으로 정의하세요. 어떤 Provider든 이 인터페이스를 구현할 수 있어, 같은 UI 컴포넌트가 완전히 다른 상태 구현과 작동할 수 있습니다.
|
|
13
|
+
|
|
14
|
+
**핵심 원칙:** Lift state, compose internals, make state dependency-injectable.
|
|
15
|
+
|
|
16
|
+
**Incorrect (특정 상태 구현에 결합):**
|
|
17
|
+
|
|
18
|
+
```tsx
|
|
19
|
+
// ❌ 특정 훅에 강하게 결합
|
|
20
|
+
function ComposerInput() {
|
|
21
|
+
const { input, setInput } = useChannelComposerState();
|
|
22
|
+
return <TextInput value={input} onChangeText={setInput} />;
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
**Correct (제네릭 인터페이스로 의존성 주입):**
|
|
27
|
+
|
|
28
|
+
```tsx
|
|
29
|
+
// ✅ 어떤 Provider든 구현할 수 있는 제네릭 인터페이스
|
|
30
|
+
interface ComposerState {
|
|
31
|
+
input: string;
|
|
32
|
+
attachments: Attachment[];
|
|
33
|
+
isSubmitting: boolean;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
interface ComposerActions {
|
|
37
|
+
update: (updater: (state: ComposerState) => ComposerState) => void;
|
|
38
|
+
submit: () => void;
|
|
39
|
+
addAttachment: (file: File) => void;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
interface ComposerMeta {
|
|
43
|
+
inputRef: React.RefObject<HTMLTextAreaElement>;
|
|
44
|
+
maxLength?: number;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
interface ComposerContextValue {
|
|
48
|
+
state: ComposerState;
|
|
49
|
+
actions: ComposerActions;
|
|
50
|
+
meta: ComposerMeta;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const ComposerContext = createContext<ComposerContextValue | null>(null);
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
**UI 컴포넌트는 인터페이스만 소비:**
|
|
57
|
+
|
|
58
|
+
```tsx
|
|
59
|
+
function ComposerInput() {
|
|
60
|
+
const {
|
|
61
|
+
state,
|
|
62
|
+
actions: { update },
|
|
63
|
+
meta,
|
|
64
|
+
} = use(ComposerContext)!;
|
|
65
|
+
|
|
66
|
+
// 이 컴포넌트는 인터페이스를 구현한 어떤 Provider와도 작동
|
|
67
|
+
return (
|
|
68
|
+
<textarea
|
|
69
|
+
ref={meta.inputRef}
|
|
70
|
+
value={state.input}
|
|
71
|
+
maxLength={meta.maxLength}
|
|
72
|
+
onChange={(e) => update((s) => ({ ...s, input: e.target.value }))}
|
|
73
|
+
/>
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
**서로 다른 Provider가 같은 인터페이스 구현:**
|
|
79
|
+
|
|
80
|
+
```tsx
|
|
81
|
+
// Provider A: 임시 폼을 위한 로컬 상태
|
|
82
|
+
function ForwardMessageProvider({ children }: { children: React.ReactNode }) {
|
|
83
|
+
const [state, setState] = useState(initialState);
|
|
84
|
+
const inputRef = useRef<HTMLTextAreaElement>(null);
|
|
85
|
+
const submit = useForwardMessage();
|
|
86
|
+
|
|
87
|
+
return (
|
|
88
|
+
<ComposerContext value={{
|
|
89
|
+
state,
|
|
90
|
+
actions: { update: setState, submit, addAttachment: ... },
|
|
91
|
+
meta: { inputRef },
|
|
92
|
+
}}>
|
|
93
|
+
{children}
|
|
94
|
+
</ComposerContext>
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Provider B: 채널을 위한 전역 동기화 상태
|
|
99
|
+
function ChannelProvider({ channelId, children }: Props) {
|
|
100
|
+
const { state, update, submit } = useGlobalChannel(channelId);
|
|
101
|
+
const inputRef = useRef<HTMLTextAreaElement>(null);
|
|
102
|
+
|
|
103
|
+
return (
|
|
104
|
+
<ComposerContext value={{
|
|
105
|
+
state,
|
|
106
|
+
actions: { update, submit, addAttachment: ... },
|
|
107
|
+
meta: { inputRef, maxLength: 2000 },
|
|
108
|
+
}}>
|
|
109
|
+
{children}
|
|
110
|
+
</ComposerContext>
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
**같은 UI가 두 Provider와 모두 작동:**
|
|
116
|
+
|
|
117
|
+
```tsx
|
|
118
|
+
// ForwardMessageProvider와 작동 (로컬 상태)
|
|
119
|
+
<ForwardMessageProvider>
|
|
120
|
+
<Composer.Frame>
|
|
121
|
+
<Composer.Input />
|
|
122
|
+
<Composer.Submit />
|
|
123
|
+
</Composer.Frame>
|
|
124
|
+
</ForwardMessageProvider>
|
|
125
|
+
|
|
126
|
+
// ChannelProvider와 작동 (전역 동기화 상태)
|
|
127
|
+
<ChannelProvider channelId="abc">
|
|
128
|
+
<Composer.Frame>
|
|
129
|
+
<Composer.Input />
|
|
130
|
+
<Composer.Submit />
|
|
131
|
+
</Composer.Frame>
|
|
132
|
+
</ChannelProvider>
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## Mandu Island에서의 활용
|
|
136
|
+
|
|
137
|
+
```tsx
|
|
138
|
+
// Island 컴포넌트는 인터페이스만 알면 됨
|
|
139
|
+
// slot에서 어떤 Provider를 사용하든 같은 Island 재사용 가능
|
|
140
|
+
|
|
141
|
+
// spec/slots/forward.slot.ts → ForwardMessageProvider 사용
|
|
142
|
+
// spec/slots/channel.slot.ts → ChannelProvider 사용
|
|
143
|
+
// 둘 다 같은 Composer Island 컴포넌트 사용
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
UI는 재사용 가능한 조각들이고, 상태는 Provider가 주입합니다. Provider를 바꾸면 UI는 그대로!
|
|
147
|
+
|
|
148
|
+
Reference: [Context Interface Pattern](https://kentcdodds.com/blog/how-to-use-react-context-effectively)
|