@bovinphang/frontend-craft 2.8.0 → 2.9.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/.claude-plugin/marketplace.json +3 -3
- package/.claude-plugin/plugin.json +1 -1
- package/CHANGELOG.md +378 -339
- package/CHANGELOG.zh-CN.md +377 -338
- package/CONTRIBUTING.md +371 -361
- package/CONTRIBUTING.zh-CN.md +371 -361
- package/README.md +545 -493
- package/README.openclaw.md +359 -320
- package/README.openclaw.zh-CN.md +359 -320
- package/README.zh-CN.md +545 -493
- package/agents/fec-code-reviewer.md +24 -3
- package/agents/fec-debugger.md +1 -1
- package/agents/fec-doc-updater.md +1 -1
- package/agents/fec-e2e-runner.md +1 -1
- package/agents/fec-figma-implementer.md +1 -1
- package/agents/fec-performance-optimizer.md +1 -1
- package/agents/fec-refactor-cleaner.md +4 -1
- package/agents/fec-refactoring-expert.md +81 -0
- package/agents/fec-security-reviewer.md +17 -1
- package/agents/fec-test-planner.md +1 -1
- package/agents/fec-typescript-reviewer.md +24 -8
- package/agents/fec-ui-checker.md +11 -11
- package/commands/fec-debug.md +1 -1
- package/commands/fec-refactor-plan.md +17 -0
- package/commands/fec-refactor.md +18 -0
- package/commands/fec-review.md +40 -10
- package/commands/fec-scaffold.md +1 -1
- package/commands/fec-smell.md +17 -0
- package/commands/fec-tdd.md +6 -2
- package/dist/bin/frontend-craft.js +190 -38
- package/dist/hooks/fec-run-tests.js +5 -1
- package/dist/hooks/fec-session-start.js +1 -1
- package/docs/example-prompts.md +157 -140
- package/docs/ja-JP/README.md +534 -493
- package/docs/ko-KR/README.md +534 -493
- package/docs/project-structure.md +151 -131
- package/docs/refactoring/README.md +50 -0
- package/docs/refactoring/catalog.md +105 -0
- package/docs/refactoring/smell-refactoring-matrix.md +41 -0
- package/docs/review-and-diagram-workflows.md +39 -0
- package/docs/runtimes/antigravity.md +18 -10
- package/docs/runtimes/augment.md +18 -10
- package/docs/runtimes/claude.md +191 -177
- package/docs/runtimes/claude.zh-CN.md +189 -175
- package/docs/runtimes/cline.md +18 -10
- package/docs/runtimes/codebuddy.md +18 -10
- package/docs/runtimes/codex.md +18 -10
- package/docs/runtimes/compatibility.md +27 -0
- package/docs/runtimes/copilot.md +18 -10
- package/docs/runtimes/cursor.md +18 -10
- package/docs/runtimes/gemini.md +18 -10
- package/docs/runtimes/kilo.md +18 -10
- package/docs/runtimes/openclaw.md +18 -10
- package/docs/runtimes/opencode.md +18 -10
- package/docs/runtimes/qoder.md +18 -19
- package/docs/runtimes/trae.md +18 -10
- package/docs/runtimes/windsurf.md +18 -10
- package/docs/superpowers/plans/2026-09-26-content-integrity.md +145 -0
- package/docs/superpowers/plans/2026-09-26-diagram-quality.md +170 -0
- package/docs/superpowers/specs/2026-09-26-diagram-quality-design.md +77 -0
- package/docs/superpowers/specs/2026-09-26-project-optimization-design.md +95 -0
- package/docs/zh-CN/example-prompts.md +157 -140
- package/docs/zh-CN/project-structure.md +148 -128
- package/docs/zh-CN/review-and-diagram-workflows.md +39 -0
- package/docs/zh-TW/README.md +534 -493
- package/localized/zh-CN/agents/fec-code-reviewer.md +22 -3
- package/localized/zh-CN/agents/fec-refactor-cleaner.md +3 -0
- package/localized/zh-CN/agents/fec-refactoring-expert.md +53 -0
- package/localized/zh-CN/agents/fec-security-reviewer.md +16 -0
- package/localized/zh-CN/agents/fec-typescript-reviewer.md +23 -7
- package/localized/zh-CN/commands/fec-refactor-plan.md +15 -0
- package/localized/zh-CN/commands/fec-refactor.md +14 -0
- package/localized/zh-CN/commands/fec-review.md +40 -9
- package/localized/zh-CN/commands/fec-smell.md +13 -0
- package/localized/zh-CN/commands/fec-tdd.md +4 -0
- package/localized/zh-CN/skills/eval_queries.json +244 -0
- package/localized/zh-CN/skills/fec-code-review/SKILL.md +20 -1
- package/localized/zh-CN/skills/fec-code-review/references/report-template.md +11 -1
- package/localized/zh-CN/skills/fec-code-smells/SKILL.md +33 -0
- package/localized/zh-CN/skills/fec-code-smells/references/detection-guide.md +25 -0
- package/localized/zh-CN/skills/fec-code-smells/references/smell-catalog.md +817 -0
- package/localized/zh-CN/skills/fec-code-smells/references/smell-to-refactoring-map.md +265 -0
- package/localized/zh-CN/skills/fec-image-generation/SKILL.md +31 -1
- package/localized/zh-CN/skills/fec-image-generation/assets/quality-examples/README.md +14 -0
- package/localized/zh-CN/skills/fec-image-generation/assets/quality-examples/architecture.json +121 -0
- package/localized/zh-CN/skills/fec-image-generation/assets/quality-examples/invalid-explicit.json +41 -0
- package/localized/zh-CN/skills/fec-image-generation/assets/quality-examples/sequence.json +53 -0
- package/localized/zh-CN/skills/fec-image-generation/assets/quality-examples/sequence.mmd +21 -0
- package/localized/zh-CN/skills/fec-image-generation/assets/quality-examples/workflow.json +98 -0
- package/localized/zh-CN/skills/fec-image-generation/assets/quality-examples/workflow.mmd +7 -0
- package/localized/zh-CN/skills/fec-image-generation/references/diagram-workflows.md +10 -3
- package/localized/zh-CN/skills/fec-image-generation/references/html-technical-diagrams.md +8 -1
- package/localized/zh-CN/skills/fec-image-generation/references/png-qa-autofix.md +9 -2
- package/localized/zh-CN/skills/fec-image-generation/scripts/diagram-browser.mjs +90 -0
- package/localized/zh-CN/skills/fec-image-generation/scripts/diagram-layout.mjs +176 -0
- package/localized/zh-CN/skills/fec-image-generation/scripts/export-diagram.mjs +48 -80
- package/localized/zh-CN/skills/fec-image-generation/scripts/mermaid-render.mjs +64 -0
- package/localized/zh-CN/skills/fec-image-generation/scripts/png-qa.mjs +35 -4
- package/localized/zh-CN/skills/fec-image-generation/scripts/tech-diagram-render.mjs +193 -53
- package/localized/zh-CN/skills/fec-refactor-clean/SKILL.md +3 -0
- package/localized/zh-CN/skills/fec-refactoring/SKILL.md +83 -0
- package/localized/zh-CN/skills/fec-refactoring/references/principles.md +43 -0
- package/localized/zh-CN/skills/fec-refactoring/references/refactoring-vs-feature-change.md +25 -0
- package/localized/zh-CN/skills/fec-refactoring/references/when-to-refactor.md +17 -0
- package/localized/zh-CN/skills/fec-refactoring/references/workflow.md +59 -0
- package/localized/zh-CN/skills/fec-refactoring-api/SKILL.md +25 -0
- package/localized/zh-CN/skills/fec-refactoring-api/references/api-refactorings.md +496 -0
- package/localized/zh-CN/skills/fec-refactoring-catalog/SKILL.md +21 -0
- package/localized/zh-CN/skills/fec-refactoring-catalog/references/catalog-index.md +99 -0
- package/localized/zh-CN/skills/fec-refactoring-catalog/references/composition-guide.md +49 -0
- package/localized/zh-CN/skills/fec-refactoring-catalog/references/selection-guide.md +41 -0
- package/localized/zh-CN/skills/fec-refactoring-control/SKILL.md +25 -0
- package/localized/zh-CN/skills/fec-refactoring-control/references/conditional-refactorings.md +299 -0
- package/localized/zh-CN/skills/fec-refactoring-data/SKILL.md +25 -0
- package/localized/zh-CN/skills/fec-refactoring-data/references/data-refactorings.md +248 -0
- package/localized/zh-CN/skills/fec-refactoring-encapsulation/SKILL.md +25 -0
- package/localized/zh-CN/skills/fec-refactoring-encapsulation/references/encapsulation-refactorings.md +452 -0
- package/localized/zh-CN/skills/fec-refactoring-functions/SKILL.md +25 -0
- package/localized/zh-CN/skills/fec-refactoring-functions/references/function-refactorings.md +567 -0
- package/localized/zh-CN/skills/fec-refactoring-inheritance/SKILL.md +25 -0
- package/localized/zh-CN/skills/fec-refactoring-inheritance/references/inheritance-refactorings.md +550 -0
- package/localized/zh-CN/skills/fec-refactoring-move-features/SKILL.md +25 -0
- package/localized/zh-CN/skills/fec-refactoring-move-features/references/moving-refactorings.md +453 -0
- package/localized/zh-CN/skills/fec-refactoring-validation/SKILL.md +52 -0
- package/localized/zh-CN/skills/fec-refactoring-validation/references/behavior-preservation.md +15 -0
- package/localized/zh-CN/skills/fec-refactoring-validation/references/refactoring-test-checklist.md +25 -0
- package/localized/zh-CN/skills/fec-security-review/SKILL.md +16 -0
- package/localized/zh-CN/skills/fec-security-review/references/report-template.md +10 -0
- package/localized/zh-CN/skills/fec-tdd-workflow/SKILL.md +3 -0
- package/localized/zh-CN/skills/metadata.json +408 -50
- package/localized/zh-CN/skills/relations.json +271 -3
- package/localized/zh-CN/templates/shared/rules/fec-agent-workflow.md +1 -0
- package/openclaw.plugin.json +2 -3
- package/package.json +27 -17
- package/skills/eval_queries.json +244 -0
- package/skills/fec-code-review/SKILL.md +20 -1
- package/skills/fec-code-review/references/report-template.md +11 -1
- package/skills/fec-code-smells/SKILL.md +33 -0
- package/skills/fec-code-smells/references/detection-guide.md +25 -0
- package/skills/fec-code-smells/references/smell-catalog.md +861 -0
- package/skills/fec-code-smells/references/smell-to-refactoring-map.md +265 -0
- package/skills/fec-data-fetching/SKILL.md +1 -1
- package/skills/fec-image-generation/SKILL.md +31 -1
- package/skills/fec-image-generation/assets/quality-examples/README.md +14 -0
- package/skills/fec-image-generation/assets/quality-examples/architecture.json +121 -0
- package/skills/fec-image-generation/assets/quality-examples/invalid-explicit.json +41 -0
- package/skills/fec-image-generation/assets/quality-examples/sequence.json +53 -0
- package/skills/fec-image-generation/assets/quality-examples/sequence.mmd +21 -0
- package/skills/fec-image-generation/assets/quality-examples/workflow.json +98 -0
- package/skills/fec-image-generation/assets/quality-examples/workflow.mmd +7 -0
- package/skills/fec-image-generation/references/diagram-workflows.md +10 -3
- package/skills/fec-image-generation/references/html-technical-diagrams.md +8 -1
- package/skills/fec-image-generation/references/png-qa-autofix.md +9 -2
- package/skills/fec-image-generation/scripts/diagram-browser.mjs +90 -0
- package/skills/fec-image-generation/scripts/diagram-layout.mjs +176 -0
- package/skills/fec-image-generation/scripts/export-diagram.mjs +48 -80
- package/skills/fec-image-generation/scripts/mermaid-render.mjs +64 -0
- package/skills/fec-image-generation/scripts/png-qa.mjs +35 -4
- package/skills/fec-image-generation/scripts/tech-diagram-render.mjs +193 -53
- package/skills/fec-legacy-web-standard/SKILL.md +1 -1
- package/skills/fec-refactor-clean/SKILL.md +3 -0
- package/skills/fec-refactoring/SKILL.md +83 -0
- package/skills/fec-refactoring/references/principles.md +60 -0
- package/skills/fec-refactoring/references/refactoring-vs-feature-change.md +27 -0
- package/skills/fec-refactoring/references/when-to-refactor.md +31 -0
- package/skills/fec-refactoring/references/workflow.md +90 -0
- package/skills/fec-refactoring-api/SKILL.md +25 -0
- package/skills/fec-refactoring-api/references/api-refactorings.md +496 -0
- package/skills/fec-refactoring-catalog/SKILL.md +28 -0
- package/skills/fec-refactoring-catalog/references/catalog-index.md +99 -0
- package/skills/fec-refactoring-catalog/references/composition-guide.md +49 -0
- package/skills/fec-refactoring-catalog/references/selection-guide.md +47 -0
- package/skills/fec-refactoring-control/SKILL.md +25 -0
- package/skills/fec-refactoring-control/references/conditional-refactorings.md +299 -0
- package/skills/fec-refactoring-data/SKILL.md +25 -0
- package/skills/fec-refactoring-data/references/data-refactorings.md +248 -0
- package/skills/fec-refactoring-encapsulation/SKILL.md +25 -0
- package/skills/fec-refactoring-encapsulation/references/encapsulation-refactorings.md +452 -0
- package/skills/fec-refactoring-functions/SKILL.md +25 -0
- package/skills/fec-refactoring-functions/references/function-refactorings.md +567 -0
- package/skills/fec-refactoring-inheritance/SKILL.md +25 -0
- package/skills/fec-refactoring-inheritance/references/inheritance-refactorings.md +550 -0
- package/skills/fec-refactoring-move-features/SKILL.md +25 -0
- package/skills/fec-refactoring-move-features/references/moving-refactorings.md +453 -0
- package/skills/fec-refactoring-validation/SKILL.md +59 -0
- package/skills/fec-refactoring-validation/references/behavior-preservation.md +53 -0
- package/skills/fec-refactoring-validation/references/refactoring-test-checklist.md +42 -0
- package/skills/fec-security-review/SKILL.md +16 -0
- package/skills/fec-security-review/references/report-template.md +10 -0
- package/skills/fec-tdd-workflow/SKILL.md +5 -1
- package/skills/metadata.json +434 -71
- package/skills/relations.json +264 -0
- package/templates/shared/rules/fec-agent-workflow.md +1 -0
- package/docs/superpowers/plans/2026-05-29-fec-debug.md +0 -491
- package/docs/superpowers/specs/2026-05-29-fec-debug-design.md +0 -340
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
# Data Refactorings
|
|
2
|
+
|
|
3
|
+
These cards transform the supplied standard catalog into concise operational guidance for frontend agents. Standard IDs/names are preserved; examples and framework adaptations are original.
|
|
4
|
+
|
|
5
|
+
## RF-SPLIT-VARIABLE — Split Variable
|
|
6
|
+
|
|
7
|
+
### Intent
|
|
8
|
+
Give distinct assignments distinct variables when one variable currently represents more than one thing.
|
|
9
|
+
|
|
10
|
+
### Typical Signals
|
|
11
|
+
- A local variable is reassigned for unrelated purposes or a parameter is overwritten.
|
|
12
|
+
|
|
13
|
+
### Avoid When
|
|
14
|
+
- Loop counters or deliberate accumulators are not automatically candidates.
|
|
15
|
+
|
|
16
|
+
### Preconditions
|
|
17
|
+
- Current observable behavior and affected callers are understood.
|
|
18
|
+
- The target scope is inside a declared diff budget and can be verified after this one primary transformation.
|
|
19
|
+
|
|
20
|
+
### Mechanics
|
|
21
|
+
1. Identify each semantic role of the variable.
|
|
22
|
+
2. Introduce a separate variable for the later role.
|
|
23
|
+
3. Replace reads belonging to that role.
|
|
24
|
+
4. Repeat until each variable has one meaning.
|
|
25
|
+
|
|
26
|
+
### Behavior-Preservation Checkpoints
|
|
27
|
+
- Compare inputs, outputs, exceptions, side effects, ordering, and public contracts before/after the step.
|
|
28
|
+
- For frontend code, also check UI state, events, focus, network behavior, lifecycle/state transitions, and relevant identity semantics.
|
|
29
|
+
|
|
30
|
+
### Related Code Smells
|
|
31
|
+
- `SMELL-MUTABLE-DATA`
|
|
32
|
+
|
|
33
|
+
### Composes Well With
|
|
34
|
+
- Combine only with a separately justified next transformation; no fixed sequence is required.
|
|
35
|
+
|
|
36
|
+
### JavaScript Notes
|
|
37
|
+
- Preserve equality, identity, mutation timing, serialization, and property access semantics.
|
|
38
|
+
|
|
39
|
+
### TypeScript Notes
|
|
40
|
+
- Model reference/value intent with `readonly`, narrow domain types, and explicit DTO adapters rather than unsafe casts.
|
|
41
|
+
|
|
42
|
+
### React Notes
|
|
43
|
+
- Object identity can affect state updates, memoization, dependency arrays, selectors, and reconciliation.
|
|
44
|
+
|
|
45
|
+
### Vue Notes
|
|
46
|
+
- Proxy/reference identity affects `reactive`, `ref`, `computed`, `watch`, Pinia subscriptions, and template updates.
|
|
47
|
+
|
|
48
|
+
### Frontend-Craft Adaptation
|
|
49
|
+
- Treat state identity as observable frontend behavior; choose value/reference semantics deliberately.
|
|
50
|
+
|
|
51
|
+
### Example Transformation
|
|
52
|
+
Before: `result` first stores normalized input and later stores API output. After: use `normalizedDraft` and `response`.
|
|
53
|
+
|
|
54
|
+
## RF-RENAME-FIELD — Rename Field
|
|
55
|
+
|
|
56
|
+
### Intent
|
|
57
|
+
Rename a field so the data model uses accurate domain vocabulary.
|
|
58
|
+
|
|
59
|
+
### Typical Signals
|
|
60
|
+
- A field name is ambiguous, misleading, or no longer matches the concept.
|
|
61
|
+
|
|
62
|
+
### Avoid When
|
|
63
|
+
- Treat DTO, persisted storage, URL/query, analytics, and backend field names as contracts unless a compatibility mapping exists.
|
|
64
|
+
|
|
65
|
+
### Preconditions
|
|
66
|
+
- Current observable behavior and affected callers are understood.
|
|
67
|
+
- The target scope is inside a declared diff budget and can be verified after this one primary transformation.
|
|
68
|
+
|
|
69
|
+
### Mechanics
|
|
70
|
+
1. Map internal and serialized/external uses.
|
|
71
|
+
2. Add the new field/accessor or translation at the boundary.
|
|
72
|
+
3. Migrate internal reads/writes.
|
|
73
|
+
4. Remove old compatibility only when consumers are migrated.
|
|
74
|
+
|
|
75
|
+
### Behavior-Preservation Checkpoints
|
|
76
|
+
- Compare inputs, outputs, exceptions, side effects, ordering, and public contracts before/after the step.
|
|
77
|
+
- For frontend code, also check UI state, events, focus, network behavior, lifecycle/state transitions, and relevant identity semantics.
|
|
78
|
+
|
|
79
|
+
### Related Code Smells
|
|
80
|
+
- `SMELL-MYSTERIOUS-NAME`
|
|
81
|
+
|
|
82
|
+
### Composes Well With
|
|
83
|
+
- Combine only with a separately justified next transformation; no fixed sequence is required.
|
|
84
|
+
|
|
85
|
+
### JavaScript Notes
|
|
86
|
+
- Preserve equality, identity, mutation timing, serialization, and property access semantics.
|
|
87
|
+
|
|
88
|
+
### TypeScript Notes
|
|
89
|
+
- Model reference/value intent with `readonly`, narrow domain types, and explicit DTO adapters rather than unsafe casts.
|
|
90
|
+
|
|
91
|
+
### React Notes
|
|
92
|
+
- Object identity can affect state updates, memoization, dependency arrays, selectors, and reconciliation.
|
|
93
|
+
|
|
94
|
+
### Vue Notes
|
|
95
|
+
- Proxy/reference identity affects `reactive`, `ref`, `computed`, `watch`, Pinia subscriptions, and template updates.
|
|
96
|
+
|
|
97
|
+
### Frontend-Craft Adaptation
|
|
98
|
+
- Treat state identity as observable frontend behavior; choose value/reference semantics deliberately.
|
|
99
|
+
|
|
100
|
+
### Example Transformation
|
|
101
|
+
Before: internal `mailId` actually means thread ID. After: rename to `threadId` internally while preserving backend DTO mapping if the API still sends `mailId`.
|
|
102
|
+
|
|
103
|
+
## RF-REPLACE-DERIVED-VARIABLE-WITH-QUERY — Replace Derived Variable with Query
|
|
104
|
+
|
|
105
|
+
### Intent
|
|
106
|
+
Compute derived state from its source instead of manually keeping a stored duplicate synchronized.
|
|
107
|
+
|
|
108
|
+
### Typical Signals
|
|
109
|
+
- A stored field can be deterministically derived and update paths can drift.
|
|
110
|
+
|
|
111
|
+
### Avoid When
|
|
112
|
+
- Avoid naive recomputation when the calculation is expensive; use memoization only if identity/dependency semantics are understood.
|
|
113
|
+
|
|
114
|
+
### Preconditions
|
|
115
|
+
- Current observable behavior and affected callers are understood.
|
|
116
|
+
- The target scope is inside a declared diff budget and can be verified after this one primary transformation.
|
|
117
|
+
|
|
118
|
+
### Mechanics
|
|
119
|
+
1. Define the derivation as a query/computed value.
|
|
120
|
+
2. Replace reads of stored derived state.
|
|
121
|
+
3. Remove synchronization writes.
|
|
122
|
+
4. Verify recomputation cost, memoization, and reactive dependencies.
|
|
123
|
+
|
|
124
|
+
### Behavior-Preservation Checkpoints
|
|
125
|
+
- Compare inputs, outputs, exceptions, side effects, ordering, and public contracts before/after the step.
|
|
126
|
+
- For frontend code, also check UI state, events, focus, network behavior, lifecycle/state transitions, and relevant identity semantics.
|
|
127
|
+
|
|
128
|
+
### Related Code Smells
|
|
129
|
+
- `SMELL-MUTABLE-DATA`
|
|
130
|
+
|
|
131
|
+
### Composes Well With
|
|
132
|
+
- Combine only with a separately justified next transformation; no fixed sequence is required.
|
|
133
|
+
|
|
134
|
+
### JavaScript Notes
|
|
135
|
+
- Preserve equality, identity, mutation timing, serialization, and property access semantics.
|
|
136
|
+
|
|
137
|
+
### TypeScript Notes
|
|
138
|
+
- Model reference/value intent with `readonly`, narrow domain types, and explicit DTO adapters rather than unsafe casts.
|
|
139
|
+
|
|
140
|
+
### React Notes
|
|
141
|
+
- Object identity can affect state updates, memoization, dependency arrays, selectors, and reconciliation.
|
|
142
|
+
|
|
143
|
+
### Vue Notes
|
|
144
|
+
- Proxy/reference identity affects `reactive`, `ref`, `computed`, `watch`, Pinia subscriptions, and template updates.
|
|
145
|
+
|
|
146
|
+
### Frontend-Craft Adaptation
|
|
147
|
+
- Treat state identity as observable frontend behavior; choose value/reference semantics deliberately.
|
|
148
|
+
|
|
149
|
+
### Example Transformation
|
|
150
|
+
Before: React state stores both `items` and `totalCount = items.length`. After: derive the count, using memoization only if the real calculation warrants it.
|
|
151
|
+
|
|
152
|
+
## RF-CHANGE-REFERENCE-TO-VALUE — Change Reference to Value
|
|
153
|
+
|
|
154
|
+
### Intent
|
|
155
|
+
Use immutable value semantics when objects are defined entirely by their data and shared identity is unnecessary.
|
|
156
|
+
|
|
157
|
+
### Typical Signals
|
|
158
|
+
- Equivalent values should compare by content and independent replacement is safer than shared mutation.
|
|
159
|
+
|
|
160
|
+
### Avoid When
|
|
161
|
+
- Avoid when shared identity, lifecycle, caching, subscriptions, or coordinated updates are meaningful.
|
|
162
|
+
|
|
163
|
+
### Preconditions
|
|
164
|
+
- Current observable behavior and affected callers are understood.
|
|
165
|
+
- The target scope is inside a declared diff budget and can be verified after this one primary transformation.
|
|
166
|
+
|
|
167
|
+
### Mechanics
|
|
168
|
+
1. Identify identity-dependent behavior.
|
|
169
|
+
2. Make the value immutable and define equality/creation semantics.
|
|
170
|
+
3. Replace mutation with replacement.
|
|
171
|
+
4. Verify React/Vue equality/reactivity and cache behavior.
|
|
172
|
+
|
|
173
|
+
### Behavior-Preservation Checkpoints
|
|
174
|
+
- Compare inputs, outputs, exceptions, side effects, ordering, and public contracts before/after the step.
|
|
175
|
+
- For frontend code, also check UI state, events, focus, network behavior, lifecycle/state transitions, and relevant identity semantics.
|
|
176
|
+
|
|
177
|
+
### Related Code Smells
|
|
178
|
+
- `SMELL-MUTABLE-DATA`
|
|
179
|
+
|
|
180
|
+
### Composes Well With
|
|
181
|
+
- Combine only with a separately justified next transformation; no fixed sequence is required.
|
|
182
|
+
|
|
183
|
+
### JavaScript Notes
|
|
184
|
+
- Preserve equality, identity, mutation timing, serialization, and property access semantics.
|
|
185
|
+
|
|
186
|
+
### TypeScript Notes
|
|
187
|
+
- Model reference/value intent with `readonly`, narrow domain types, and explicit DTO adapters rather than unsafe casts.
|
|
188
|
+
|
|
189
|
+
### React Notes
|
|
190
|
+
- Object identity can affect state updates, memoization, dependency arrays, selectors, and reconciliation.
|
|
191
|
+
|
|
192
|
+
### Vue Notes
|
|
193
|
+
- Proxy/reference identity affects `reactive`, `ref`, `computed`, `watch`, Pinia subscriptions, and template updates.
|
|
194
|
+
|
|
195
|
+
### Frontend-Craft Adaptation
|
|
196
|
+
- Treat state identity as observable frontend behavior; choose value/reference semantics deliberately.
|
|
197
|
+
|
|
198
|
+
### Example Transformation
|
|
199
|
+
Before: a mutable `DateRange` object is shared and changed in place. After: immutable ranges are replaced as values when no shared identity is required.
|
|
200
|
+
|
|
201
|
+
## RF-CHANGE-VALUE-TO-REFERENCE — Change Value to Reference
|
|
202
|
+
|
|
203
|
+
### Intent
|
|
204
|
+
Use a canonical shared object when identity and coordinated updates matter more than independent copies.
|
|
205
|
+
|
|
206
|
+
### Typical Signals
|
|
207
|
+
- Multiple copies represent the same entity and must stay synchronized.
|
|
208
|
+
|
|
209
|
+
### Avoid When
|
|
210
|
+
- Avoid introducing a global identity map when values are naturally independent snapshots.
|
|
211
|
+
|
|
212
|
+
### Preconditions
|
|
213
|
+
- Current observable behavior and affected callers are understood.
|
|
214
|
+
- The target scope is inside a declared diff budget and can be verified after this one primary transformation.
|
|
215
|
+
|
|
216
|
+
### Mechanics
|
|
217
|
+
1. Choose a stable identity key and owner/registry.
|
|
218
|
+
2. Resolve values to the canonical reference.
|
|
219
|
+
3. Migrate consumers incrementally.
|
|
220
|
+
4. Verify update propagation, cache lifetime, and serialization boundaries.
|
|
221
|
+
|
|
222
|
+
### Behavior-Preservation Checkpoints
|
|
223
|
+
- Compare inputs, outputs, exceptions, side effects, ordering, and public contracts before/after the step.
|
|
224
|
+
- For frontend code, also check UI state, events, focus, network behavior, lifecycle/state transitions, and relevant identity semantics.
|
|
225
|
+
|
|
226
|
+
### Related Code Smells
|
|
227
|
+
- No single code smell required; select from concrete structural evidence.
|
|
228
|
+
|
|
229
|
+
### Composes Well With
|
|
230
|
+
- Combine only with a separately justified next transformation; no fixed sequence is required.
|
|
231
|
+
|
|
232
|
+
### JavaScript Notes
|
|
233
|
+
- Preserve equality, identity, mutation timing, serialization, and property access semantics.
|
|
234
|
+
|
|
235
|
+
### TypeScript Notes
|
|
236
|
+
- Model reference/value intent with `readonly`, narrow domain types, and explicit DTO adapters rather than unsafe casts.
|
|
237
|
+
|
|
238
|
+
### React Notes
|
|
239
|
+
- Object identity can affect state updates, memoization, dependency arrays, selectors, and reconciliation.
|
|
240
|
+
|
|
241
|
+
### Vue Notes
|
|
242
|
+
- Proxy/reference identity affects `reactive`, `ref`, `computed`, `watch`, Pinia subscriptions, and template updates.
|
|
243
|
+
|
|
244
|
+
### Frontend-Craft Adaptation
|
|
245
|
+
- Treat state identity as observable frontend behavior; choose value/reference semantics deliberately.
|
|
246
|
+
|
|
247
|
+
### Example Transformation
|
|
248
|
+
Before: each message stores a copied sender object. After: sender IDs resolve to canonical contact entities when shared updates must propagate.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: fec-refactoring-encapsulation
|
|
3
|
+
description: Use when behavior-preserving frontend refactoring focuses on record, collection, value, responsibility, delegation, or algorithm boundaries, and the selected technique needs family-specific mechanics, risks, and JavaScript/TypeScript/React/Vue adaptation.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Encapsulation Refactorings
|
|
7
|
+
|
|
8
|
+
## Overview
|
|
9
|
+
Use this family after evidence identifies a fitting structural transformation. Apply one primary technique at a time and verify immediately.
|
|
10
|
+
|
|
11
|
+
## Procedure
|
|
12
|
+
1. Confirm the selected technique and its preconditions in [Encapsulation Refactorings](references/encapsulation-refactorings.md).
|
|
13
|
+
2. Record affected behavior and a diff budget.
|
|
14
|
+
3. Apply only the selected technique's smallest viable step.
|
|
15
|
+
4. Verify the step before composing another transformation.
|
|
16
|
+
5. Stop and reassess when public contracts, lifecycle, state identity, or actual scope exceed expectations.
|
|
17
|
+
|
|
18
|
+
## Quick Reference
|
|
19
|
+
The family reference contains 9 canonical techniques with intent, signals, avoid conditions, mechanics, preservation checkpoints, smell links, composition hints, JavaScript/TypeScript notes, React/Vue notes, adaptation guidance, and original frontend examples.
|
|
20
|
+
|
|
21
|
+
## Common Mistakes
|
|
22
|
+
- Choosing a technique by name without checking its preconditions.
|
|
23
|
+
- Combining several structural intentions in one diff.
|
|
24
|
+
- Assuming a classical class-based form is mandatory in modern frontend code.
|
|
25
|
+
- Treating passing tests as proof when the relevant behavior is not covered.
|