@bovinphang/frontend-craft 2.7.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 -305
- package/CHANGELOG.zh-CN.md +377 -304
- package/CONTRIBUTING.md +371 -361
- package/CONTRIBUTING.zh-CN.md +371 -361
- package/README.md +545 -493
- package/README.openclaw.md +359 -264
- package/README.openclaw.zh-CN.md +359 -264
- package/README.zh-CN.md +545 -493
- package/agents/fec-architect.md +70 -70
- package/agents/fec-code-reviewer.md +103 -82
- package/agents/fec-debugger.md +20 -20
- package/agents/fec-design-token-mapper.md +36 -36
- package/agents/fec-doc-updater.md +13 -13
- package/agents/fec-e2e-runner.md +45 -45
- package/agents/fec-figma-implementer.md +59 -59
- package/agents/fec-performance-optimizer.md +128 -128
- package/agents/fec-refactor-cleaner.md +17 -14
- package/agents/fec-refactoring-expert.md +81 -0
- package/agents/fec-security-reviewer.md +82 -67
- package/agents/fec-test-planner.md +27 -27
- package/agents/fec-typescript-reviewer.md +103 -87
- package/agents/fec-ui-checker.md +64 -64
- package/commands/fec-debug.md +19 -19
- package/commands/fec-doc-sync.md +11 -11
- package/commands/fec-init.md +37 -38
- package/commands/fec-plan.md +58 -58
- package/commands/fec-refactor-clean.md +11 -11
- package/commands/fec-refactor-plan.md +17 -0
- package/commands/fec-refactor.md +18 -0
- package/commands/fec-review.md +71 -41
- package/commands/fec-scaffold.md +41 -41
- package/commands/fec-smell.md +17 -0
- package/commands/fec-tdd.md +17 -13
- package/dist/bin/frontend-craft.js +190 -36
- package/dist/hooks/fec-run-tests.js +5 -1
- package/dist/hooks/fec-session-start.js +1 -1
- package/docs/example-prompts.md +157 -137
- package/docs/ja-JP/README.md +534 -493
- package/docs/ko-KR/README.md +534 -493
- package/docs/project-structure.md +151 -123
- 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 -137
- package/docs/zh-CN/project-structure.md +148 -123
- 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-architect.md +125 -0
- package/localized/zh-CN/agents/fec-code-reviewer.md +171 -0
- package/localized/zh-CN/agents/fec-debugger.md +44 -0
- package/localized/zh-CN/agents/fec-design-token-mapper.md +75 -0
- package/localized/zh-CN/agents/fec-doc-updater.md +30 -0
- package/localized/zh-CN/agents/fec-e2e-runner.md +107 -0
- package/localized/zh-CN/agents/fec-figma-implementer.md +104 -0
- package/localized/zh-CN/agents/fec-performance-optimizer.md +293 -0
- package/localized/zh-CN/agents/fec-refactor-cleaner.md +35 -0
- package/localized/zh-CN/agents/fec-refactoring-expert.md +53 -0
- package/localized/zh-CN/agents/fec-security-reviewer.md +132 -0
- package/localized/zh-CN/agents/fec-test-planner.md +50 -0
- package/localized/zh-CN/agents/fec-typescript-reviewer.md +158 -0
- package/localized/zh-CN/agents/fec-ui-checker.md +120 -0
- package/localized/zh-CN/commands/fec-debug.md +30 -0
- package/localized/zh-CN/commands/fec-doc-sync.md +19 -0
- package/localized/zh-CN/commands/fec-init.md +70 -0
- package/localized/zh-CN/commands/fec-plan.md +94 -0
- package/localized/zh-CN/commands/fec-refactor-clean.md +19 -0
- 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 +97 -0
- package/localized/zh-CN/commands/fec-scaffold.md +205 -0
- package/localized/zh-CN/commands/fec-smell.md +13 -0
- package/localized/zh-CN/commands/fec-tdd.md +25 -0
- package/localized/zh-CN/skills/TEMPLATE.md +155 -0
- package/localized/zh-CN/skills/eval_queries.json +1257 -0
- package/localized/zh-CN/skills/fec-accessibility-check/SKILL.md +39 -0
- package/localized/zh-CN/skills/fec-accessibility-check/references/report-template.md +23 -0
- package/localized/zh-CN/skills/fec-accessibility-check/references/screen-reader-testing.md +33 -0
- package/localized/zh-CN/skills/fec-alchemy/SKILL.md +74 -0
- package/localized/zh-CN/skills/fec-alchemy/assets/absorption-plan-template.md +47 -0
- package/localized/zh-CN/skills/fec-alchemy/assets/intake-template.md +55 -0
- package/localized/zh-CN/skills/fec-alchemy/assets/review-checklist.md +31 -0
- package/localized/zh-CN/skills/fec-alchemy/references/methodology.md +94 -0
- package/localized/zh-CN/skills/fec-alchemy/references/originality-and-licensing.md +57 -0
- package/localized/zh-CN/skills/fec-api-integration/SKILL.md +78 -0
- package/localized/zh-CN/skills/fec-api-integration/references/integration-patterns.md +80 -0
- package/localized/zh-CN/skills/fec-backend-requirements-handoff/SKILL.md +45 -0
- package/localized/zh-CN/skills/fec-browser-storage/SKILL.md +34 -0
- package/localized/zh-CN/skills/fec-browser-storage/references/storage-patterns.md +65 -0
- package/localized/zh-CN/skills/fec-canvas-threejs/SKILL.md +66 -0
- package/localized/zh-CN/skills/fec-canvas-threejs/references/rendering-patterns.md +67 -0
- package/localized/zh-CN/skills/fec-canvas-threejs/references/shader-webgl-patterns.md +67 -0
- package/localized/zh-CN/skills/fec-code-review/SKILL.md +162 -0
- package/localized/zh-CN/skills/fec-code-review/references/report-template.md +39 -0
- 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-component-testing/SKILL.md +119 -0
- package/localized/zh-CN/skills/fec-data-fetching/SKILL.md +62 -0
- package/localized/zh-CN/skills/fec-data-fetching/references/query-patterns.md +103 -0
- package/localized/zh-CN/skills/fec-debug-framework/SKILL.md +157 -0
- package/localized/zh-CN/skills/fec-debug-framework/references/report-template.md +58 -0
- package/localized/zh-CN/skills/fec-dependency-upgrade/SKILL.md +34 -0
- package/localized/zh-CN/skills/fec-dependency-upgrade/references/dependency-upgrade-workflow.md +56 -0
- package/localized/zh-CN/skills/fec-doc-sync/SKILL.md +39 -0
- package/localized/zh-CN/skills/fec-drawio-studio/SKILL.md +73 -0
- package/localized/zh-CN/skills/fec-drawio-studio/data/THIRD_PARTY_NOTICES.md +10 -0
- package/localized/zh-CN/skills/fec-drawio-studio/data/brand-icons.json +878 -0
- package/localized/zh-CN/skills/fec-drawio-studio/data/shape-index.json +83570 -0
- package/localized/zh-CN/skills/fec-drawio-studio/references/data-residency.md +27 -0
- package/localized/zh-CN/skills/fec-drawio-studio/references/diagram-patterns.md +60 -0
- package/localized/zh-CN/skills/fec-drawio-studio/references/flowchart-quality.md +49 -0
- package/localized/zh-CN/skills/fec-drawio-studio/references/layout-and-export.md +72 -0
- package/localized/zh-CN/skills/fec-drawio-studio/references/troubleshooting.md +29 -0
- package/localized/zh-CN/skills/fec-drawio-studio/references/xml-and-mermaid.md +58 -0
- package/localized/zh-CN/skills/fec-drawio-studio/scripts/brand-symbols.mjs +99 -0
- package/localized/zh-CN/skills/fec-drawio-studio/scripts/diagram-lint.mjs +205 -0
- package/localized/zh-CN/skills/fec-drawio-studio/scripts/diagram-url.mjs +102 -0
- package/localized/zh-CN/skills/fec-drawio-studio/scripts/drawio-export.mjs +134 -0
- package/localized/zh-CN/skills/fec-drawio-studio/scripts/layout-graph.mjs +107 -0
- package/localized/zh-CN/skills/fec-drawio-studio/scripts/png-embed-fix.mjs +26 -0
- package/localized/zh-CN/skills/fec-drawio-studio/scripts/scan-go-packages.mjs +36 -0
- package/localized/zh-CN/skills/fec-drawio-studio/scripts/scan-js-modules.mjs +52 -0
- package/localized/zh-CN/skills/fec-drawio-studio/scripts/scan-python-classes.mjs +30 -0
- package/localized/zh-CN/skills/fec-drawio-studio/scripts/scan-python-modules.mjs +55 -0
- package/localized/zh-CN/skills/fec-drawio-studio/scripts/scan-rust-modules.mjs +35 -0
- package/localized/zh-CN/skills/fec-drawio-studio/scripts/scan-ts-modules.mjs +7 -0
- package/localized/zh-CN/skills/fec-drawio-studio/scripts/shape-query.mjs +121 -0
- package/localized/zh-CN/skills/fec-drawio-studio/scripts/studio-core.mjs +139 -0
- package/localized/zh-CN/skills/fec-drawio-studio/styles/built-in/corporate.json +49 -0
- package/localized/zh-CN/skills/fec-drawio-studio/styles/built-in/default.json +49 -0
- package/localized/zh-CN/skills/fec-drawio-studio/styles/built-in/handdrawn.json +49 -0
- package/localized/zh-CN/skills/fec-drawio-studio/styles/schema.json +112 -0
- package/localized/zh-CN/skills/fec-e2e-testing/SKILL.md +42 -0
- package/localized/zh-CN/skills/fec-e2e-testing/references/e2e-ci-reporting.md +62 -0
- package/localized/zh-CN/skills/fec-e2e-testing/references/e2e-special-scenarios.md +52 -0
- package/localized/zh-CN/skills/fec-e2e-testing/references/e2e-visual-regression.md +60 -0
- package/localized/zh-CN/skills/fec-e2e-testing/references/playwright-patterns.md +95 -0
- package/localized/zh-CN/skills/fec-form-handling/SKILL.md +76 -0
- package/localized/zh-CN/skills/fec-form-handling/references/advanced-form-patterns.md +101 -0
- package/localized/zh-CN/skills/fec-image-generation/SKILL.md +110 -0
- package/localized/zh-CN/skills/fec-image-generation/assets/interactive-diagram.html +371 -0
- 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/artifact-routing.md +80 -0
- package/localized/zh-CN/skills/fec-image-generation/references/diagram-workflows.md +81 -0
- package/localized/zh-CN/skills/fec-image-generation/references/html-technical-diagrams.md +243 -0
- package/localized/zh-CN/skills/fec-image-generation/references/png-qa-autofix.md +37 -0
- 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 +332 -0
- package/localized/zh-CN/skills/fec-image-generation/scripts/interactive-diagram-server.mjs +654 -0
- 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 +462 -0
- package/localized/zh-CN/skills/fec-image-generation/scripts/tech-diagram-render.mjs +1537 -0
- package/localized/zh-CN/skills/fec-implement-from-design/SKILL.md +129 -0
- package/localized/zh-CN/skills/fec-implement-from-design/references/design-plan-template.md +36 -0
- package/localized/zh-CN/skills/fec-legacy-to-modern-migration/SKILL.md +46 -0
- package/localized/zh-CN/skills/fec-legacy-to-modern-migration/references/migration-execution-checklist.md +110 -0
- package/localized/zh-CN/skills/fec-legacy-to-modern-migration/references/migration-report-template.md +41 -0
- package/localized/zh-CN/skills/fec-legacy-to-modern-migration/references/migration-strategy-and-mapping.md +48 -0
- package/localized/zh-CN/skills/fec-legacy-web-standard/SKILL.md +35 -0
- package/localized/zh-CN/skills/fec-legacy-web-standard/references/legacy-patterns.md +85 -0
- package/localized/zh-CN/skills/fec-list-virtualization/SKILL.md +34 -0
- package/localized/zh-CN/skills/fec-list-virtualization/references/virtualization-patterns.md +80 -0
- package/localized/zh-CN/skills/fec-monorepo-project-standard/SKILL.md +142 -0
- package/localized/zh-CN/skills/fec-motion-interaction/SKILL.md +73 -0
- package/localized/zh-CN/skills/fec-motion-interaction/references/motion-patterns.md +112 -0
- package/localized/zh-CN/skills/fec-nextjs-project-standard/SKILL.md +123 -0
- package/localized/zh-CN/skills/fec-nuxt-project-standard/SKILL.md +122 -0
- package/localized/zh-CN/skills/fec-performance-optimization/SKILL.md +80 -0
- package/localized/zh-CN/skills/fec-performance-optimization/references/framework-performance-patterns.md +38 -0
- package/localized/zh-CN/skills/fec-performance-optimization/references/report-template.md +59 -0
- package/localized/zh-CN/skills/fec-pwa-implementation/SKILL.md +35 -0
- package/localized/zh-CN/skills/fec-pwa-implementation/references/manifest-and-icons.md +53 -0
- package/localized/zh-CN/skills/fec-pwa-implementation/references/service-worker-workbox.md +68 -0
- package/localized/zh-CN/skills/fec-react-project-standard/SKILL.md +91 -0
- package/localized/zh-CN/skills/fec-react-project-standard/references/react-performance-patterns.md +35 -0
- package/localized/zh-CN/skills/fec-react-project-standard/references/react-project-structure.md +197 -0
- package/localized/zh-CN/skills/fec-react-project-standard/references/react-quality-patterns.md +131 -0
- package/localized/zh-CN/skills/fec-react-project-standard/references/react-runtime-patterns.md +293 -0
- package/localized/zh-CN/skills/fec-refactor-clean/SKILL.md +54 -0
- package/localized/zh-CN/skills/fec-refactor-clean/references/report-template.md +42 -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-responsive-layout/SKILL.md +34 -0
- package/localized/zh-CN/skills/fec-responsive-layout/references/responsive-layout-patterns.md +70 -0
- package/localized/zh-CN/skills/fec-route-protection/SKILL.md +135 -0
- package/localized/zh-CN/skills/fec-security-review/SKILL.md +54 -0
- package/localized/zh-CN/skills/fec-security-review/references/report-template.md +37 -0
- package/localized/zh-CN/skills/fec-security-review/references/security-checklist.md +64 -0
- package/localized/zh-CN/skills/fec-source-driven-development/SKILL.md +87 -0
- package/localized/zh-CN/skills/fec-state-management/SKILL.md +140 -0
- package/localized/zh-CN/skills/fec-state-management/references/state-patterns.md +109 -0
- package/localized/zh-CN/skills/fec-storybook-component-doc/SKILL.md +37 -0
- package/localized/zh-CN/skills/fec-storybook-component-doc/references/story-patterns.md +118 -0
- package/localized/zh-CN/skills/fec-svg-animation/SKILL.md +148 -0
- package/localized/zh-CN/skills/fec-tailwind-design-system/SKILL.md +34 -0
- package/localized/zh-CN/skills/fec-tailwind-design-system/references/tailwind-system-patterns.md +59 -0
- package/localized/zh-CN/skills/fec-tdd-workflow/SKILL.md +55 -0
- package/localized/zh-CN/skills/fec-testing-strategy/SKILL.md +45 -0
- package/localized/zh-CN/skills/fec-typescript-project-standard/SKILL.md +54 -0
- package/localized/zh-CN/skills/fec-typescript-project-standard/references/type-safety-patterns.md +102 -0
- package/localized/zh-CN/skills/fec-typescript-project-standard/references/type-safety.md +148 -0
- package/localized/zh-CN/skills/fec-ui-design/SKILL.md +108 -0
- package/localized/zh-CN/skills/fec-ui-design/data/product-rules.json +231 -0
- package/localized/zh-CN/skills/fec-ui-design/data/stack-ui-rules.json +146 -0
- package/localized/zh-CN/skills/fec-ui-design/data/style-archetypes.json +373 -0
- package/localized/zh-CN/skills/fec-ui-design/data/ux-quality-rules.json +203 -0
- package/localized/zh-CN/skills/fec-ui-design/references/design-intelligence.md +97 -0
- package/localized/zh-CN/skills/fec-ui-design/references/master-page-overrides.md +30 -0
- package/localized/zh-CN/skills/fec-ui-design/references/pre-delivery-checklist.md +39 -0
- package/localized/zh-CN/skills/fec-ui-design/scripts/design-system.mjs +648 -0
- package/localized/zh-CN/skills/fec-validation-fix/SKILL.md +51 -0
- package/localized/zh-CN/skills/fec-validation-fix/references/report-template.md +43 -0
- package/localized/zh-CN/skills/fec-vite-project-standard/SKILL.md +83 -0
- package/localized/zh-CN/skills/fec-vue3-project-standard/SKILL.md +58 -0
- package/localized/zh-CN/skills/fec-vue3-project-standard/references/vue3-composables-routing.md +162 -0
- package/localized/zh-CN/skills/fec-vue3-project-standard/references/vue3-performance-patterns.md +13 -0
- package/localized/zh-CN/skills/fec-vue3-project-standard/references/vue3-project-structure.md +176 -0
- package/localized/zh-CN/skills/fec-vue3-project-standard/references/vue3-state-api-quality.md +216 -0
- package/localized/zh-CN/skills/fec-web-video-presentation/SKILL.md +61 -0
- package/localized/zh-CN/skills/fec-web-video-presentation/data/starter-themes.json +59 -0
- package/localized/zh-CN/skills/fec-web-video-presentation/references/chapter-craft.md +37 -0
- package/localized/zh-CN/skills/fec-web-video-presentation/references/content-plan.md +38 -0
- package/localized/zh-CN/skills/fec-web-video-presentation/references/recording-and-audio.md +33 -0
- package/localized/zh-CN/skills/fec-web-video-presentation/references/theme-system.md +36 -0
- package/localized/zh-CN/skills/fec-web-video-presentation/scripts/create-video-presentation.mjs +430 -0
- package/localized/zh-CN/skills/fec-web-workers/SKILL.md +35 -0
- package/localized/zh-CN/skills/fec-web-workers/references/advanced-workers.md +54 -0
- package/localized/zh-CN/skills/fec-web-workers/references/basic-worker.md +67 -0
- package/localized/zh-CN/skills/metadata.json +2004 -0
- package/localized/zh-CN/skills/relations.json +1023 -0
- package/localized/zh-CN/templates/claude/CLAUDE.md +106 -0
- package/localized/zh-CN/templates/claude/settings.json +62 -0
- package/localized/zh-CN/templates/codex/AGENTS.md +105 -0
- package/localized/zh-CN/templates/codex/config.toml +32 -0
- package/localized/zh-CN/templates/openclaw/AGENTS.md +101 -0
- package/localized/zh-CN/templates/openclaw/OPENCLAW-CONFIG.md +12 -0
- package/localized/zh-CN/templates/shared/rules/fec-agent-workflow.md +55 -0
- package/localized/zh-CN/templates/shared/rules/fec-api-layer.md +99 -0
- package/localized/zh-CN/templates/shared/rules/fec-ci-cd.md +40 -0
- package/localized/zh-CN/templates/shared/rules/fec-code-comments.md +33 -0
- package/localized/zh-CN/templates/shared/rules/fec-design-system.md +72 -0
- package/localized/zh-CN/templates/shared/rules/fec-error-handling.md +56 -0
- package/localized/zh-CN/templates/shared/rules/fec-git-conventions.md +73 -0
- package/localized/zh-CN/templates/shared/rules/fec-i18n.md +64 -0
- package/localized/zh-CN/templates/shared/rules/fec-naming-conventions.md +120 -0
- package/localized/zh-CN/templates/shared/rules/fec-performance.md +101 -0
- package/localized/zh-CN/templates/shared/rules/fec-react.md +82 -0
- package/localized/zh-CN/templates/shared/rules/fec-refactoring.md +47 -0
- package/localized/zh-CN/templates/shared/rules/fec-rendering-patterns.md +40 -0
- package/localized/zh-CN/templates/shared/rules/fec-responsive-design.md +50 -0
- package/localized/zh-CN/templates/shared/rules/fec-source-driven-development.md +31 -0
- package/localized/zh-CN/templates/shared/rules/fec-state-management.md +60 -0
- package/localized/zh-CN/templates/shared/rules/fec-testing.md +98 -0
- package/localized/zh-CN/templates/shared/rules/fec-typescript.md +112 -0
- package/localized/zh-CN/templates/shared/rules/fec-vue.md +64 -0
- package/localized/zh-CN/templates/shared/rules/fec-working-modes.md +50 -0
- package/openclaw.plugin.json +2 -3
- package/package.json +28 -17
- package/skills/TEMPLATE.md +74 -74
- package/skills/eval_queries.json +922 -678
- package/skills/fec-accessibility-check/SKILL.md +21 -21
- package/skills/fec-accessibility-check/references/report-template.md +12 -12
- package/skills/fec-accessibility-check/references/screen-reader-testing.md +24 -24
- package/skills/fec-alchemy/SKILL.md +50 -50
- package/skills/fec-alchemy/assets/absorption-plan-template.md +32 -32
- package/skills/fec-alchemy/assets/intake-template.md +55 -55
- package/skills/fec-alchemy/assets/review-checklist.md +23 -23
- package/skills/fec-alchemy/references/methodology.md +66 -66
- package/skills/fec-alchemy/references/originality-and-licensing.md +42 -42
- package/skills/fec-api-integration/SKILL.md +61 -61
- package/skills/fec-api-integration/references/integration-patterns.md +30 -30
- package/skills/fec-backend-requirements-handoff/SKILL.md +25 -25
- package/skills/fec-browser-storage/SKILL.md +16 -16
- package/skills/fec-browser-storage/references/storage-patterns.md +16 -16
- package/skills/fec-canvas-threejs/SKILL.md +21 -21
- package/skills/fec-canvas-threejs/references/rendering-patterns.md +10 -10
- package/skills/fec-canvas-threejs/references/shader-webgl-patterns.md +37 -37
- package/skills/fec-code-review/SKILL.md +113 -94
- package/skills/fec-code-review/references/report-template.md +23 -13
- 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-component-testing/SKILL.md +39 -39
- package/skills/fec-data-fetching/SKILL.md +16 -16
- package/skills/fec-data-fetching/references/query-patterns.md +27 -27
- package/skills/fec-debug-framework/SKILL.md +95 -95
- package/skills/fec-debug-framework/references/report-template.md +34 -34
- package/skills/fec-dependency-upgrade/SKILL.md +17 -17
- package/skills/fec-dependency-upgrade/references/dependency-upgrade-workflow.md +31 -31
- package/skills/fec-doc-sync/SKILL.md +23 -23
- package/skills/fec-drawio-studio/SKILL.md +42 -38
- package/skills/fec-drawio-studio/data/THIRD_PARTY_NOTICES.md +1 -1
- package/skills/fec-drawio-studio/data/shape-index.json +83570 -0
- package/skills/fec-drawio-studio/references/diagram-patterns.md +19 -0
- package/skills/fec-drawio-studio/references/flowchart-quality.md +49 -0
- package/skills/fec-drawio-studio/references/layout-and-export.md +18 -3
- package/skills/fec-drawio-studio/references/xml-and-mermaid.md +5 -1
- package/skills/fec-drawio-studio/scripts/diagram-lint.mjs +62 -0
- package/skills/fec-drawio-studio/scripts/drawio-export.mjs +134 -0
- package/skills/fec-drawio-studio/scripts/shape-query.mjs +55 -15
- package/skills/fec-e2e-testing/SKILL.md +24 -24
- package/skills/fec-e2e-testing/references/e2e-ci-reporting.md +20 -20
- package/skills/fec-e2e-testing/references/e2e-special-scenarios.md +10 -10
- package/skills/fec-e2e-testing/references/e2e-visual-regression.md +17 -17
- package/skills/fec-e2e-testing/references/playwright-patterns.md +6 -6
- package/skills/fec-form-handling/SKILL.md +21 -21
- package/skills/fec-form-handling/references/advanced-form-patterns.md +41 -41
- package/skills/fec-image-generation/SKILL.md +84 -29
- package/skills/fec-image-generation/assets/interactive-diagram.html +371 -0
- 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 +41 -3
- package/skills/fec-image-generation/references/html-technical-diagrams.md +243 -0
- 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 +332 -0
- package/skills/fec-image-generation/scripts/interactive-diagram-server.mjs +654 -0
- 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 +1537 -0
- package/skills/fec-implement-from-design/SKILL.md +81 -81
- package/skills/fec-implement-from-design/references/design-plan-template.md +16 -16
- package/skills/fec-legacy-to-modern-migration/SKILL.md +29 -29
- package/skills/fec-legacy-to-modern-migration/references/migration-execution-checklist.md +81 -81
- package/skills/fec-legacy-to-modern-migration/references/migration-report-template.md +37 -37
- package/skills/fec-legacy-to-modern-migration/references/migration-strategy-and-mapping.md +31 -31
- package/skills/fec-legacy-web-standard/SKILL.md +17 -17
- package/skills/fec-legacy-web-standard/references/legacy-patterns.md +16 -16
- package/skills/fec-list-virtualization/SKILL.md +16 -16
- package/skills/fec-list-virtualization/references/virtualization-patterns.md +31 -31
- package/skills/fec-monorepo-project-standard/SKILL.md +52 -52
- package/skills/fec-motion-interaction/SKILL.md +51 -51
- package/skills/fec-motion-interaction/references/motion-patterns.md +11 -11
- package/skills/fec-nextjs-project-standard/SKILL.md +64 -64
- package/skills/fec-nuxt-project-standard/SKILL.md +57 -57
- package/skills/fec-performance-optimization/SKILL.md +54 -54
- package/skills/fec-performance-optimization/references/framework-performance-patterns.md +23 -23
- package/skills/fec-performance-optimization/references/report-template.md +31 -31
- package/skills/fec-pwa-implementation/SKILL.md +17 -17
- package/skills/fec-pwa-implementation/references/manifest-and-icons.md +12 -12
- package/skills/fec-pwa-implementation/references/service-worker-workbox.md +13 -13
- package/skills/fec-react-project-standard/SKILL.md +72 -72
- package/skills/fec-react-project-standard/references/react-performance-patterns.md +28 -28
- package/skills/fec-react-project-standard/references/react-project-structure.md +112 -112
- package/skills/fec-react-project-standard/references/react-quality-patterns.md +72 -72
- package/skills/fec-react-project-standard/references/react-runtime-patterns.md +94 -94
- package/skills/fec-refactor-clean/SKILL.md +33 -30
- package/skills/fec-refactor-clean/references/report-template.md +23 -23
- 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-responsive-layout/SKILL.md +17 -17
- package/skills/fec-responsive-layout/references/responsive-layout-patterns.md +37 -37
- package/skills/fec-route-protection/SKILL.md +26 -26
- package/skills/fec-security-review/SKILL.md +36 -20
- package/skills/fec-security-review/references/report-template.md +22 -12
- package/skills/fec-security-review/references/security-checklist.md +27 -27
- package/skills/fec-source-driven-development/SKILL.md +59 -59
- package/skills/fec-state-management/SKILL.md +34 -34
- package/skills/fec-state-management/references/state-patterns.md +19 -19
- package/skills/fec-storybook-component-doc/SKILL.md +19 -19
- package/skills/fec-storybook-component-doc/references/story-patterns.md +12 -12
- package/skills/fec-svg-animation/SKILL.md +32 -32
- package/skills/fec-tailwind-design-system/SKILL.md +17 -17
- package/skills/fec-tailwind-design-system/references/tailwind-system-patterns.md +36 -36
- package/skills/fec-tdd-workflow/SKILL.md +32 -28
- package/skills/fec-testing-strategy/SKILL.md +29 -29
- package/skills/fec-typescript-project-standard/SKILL.md +38 -38
- package/skills/fec-typescript-project-standard/references/type-safety-patterns.md +20 -20
- package/skills/fec-typescript-project-standard/references/type-safety.md +18 -18
- package/skills/fec-ui-design/SKILL.md +90 -90
- package/skills/fec-ui-design/references/design-intelligence.md +61 -61
- package/skills/fec-ui-design/references/master-page-overrides.md +15 -15
- package/skills/fec-ui-design/references/pre-delivery-checklist.md +38 -38
- package/skills/fec-validation-fix/SKILL.md +26 -26
- package/skills/fec-validation-fix/references/report-template.md +25 -25
- package/skills/fec-vite-project-standard/SKILL.md +39 -39
- package/skills/fec-vue3-project-standard/SKILL.md +38 -38
- package/skills/fec-vue3-project-standard/references/vue3-composables-routing.md +36 -36
- package/skills/fec-vue3-project-standard/references/vue3-performance-patterns.md +8 -8
- package/skills/fec-vue3-project-standard/references/vue3-project-structure.md +112 -112
- package/skills/fec-vue3-project-standard/references/vue3-state-api-quality.md +74 -74
- package/skills/fec-web-video-presentation/SKILL.md +33 -33
- package/skills/fec-web-workers/SKILL.md +16 -16
- package/skills/fec-web-workers/references/advanced-workers.md +13 -13
- package/skills/fec-web-workers/references/basic-worker.md +8 -8
- package/skills/metadata.json +485 -116
- package/skills/relations.json +268 -0
- package/templates/claude/CLAUDE.md +60 -60
- package/templates/codex/AGENTS.md +76 -76
- package/templates/codex/config.toml +4 -4
- package/templates/openclaw/AGENTS.md +68 -68
- package/templates/openclaw/OPENCLAW-CONFIG.md +8 -8
- package/templates/shared/rules/fec-agent-workflow.md +41 -40
- package/templates/shared/rules/fec-api-layer.md +52 -52
- package/templates/shared/rules/fec-ci-cd.md +29 -29
- package/templates/shared/rules/fec-code-comments.md +22 -22
- package/templates/shared/rules/fec-design-system.md +53 -53
- package/templates/shared/rules/fec-error-handling.md +40 -40
- package/templates/shared/rules/fec-git-conventions.md +42 -42
- package/templates/shared/rules/fec-i18n.md +48 -48
- package/templates/shared/rules/fec-naming-conventions.md +91 -91
- package/templates/shared/rules/fec-performance.md +78 -78
- package/templates/shared/rules/fec-react.md +58 -58
- package/templates/shared/rules/fec-refactoring.md +34 -34
- package/templates/shared/rules/fec-rendering-patterns.md +36 -36
- package/templates/shared/rules/fec-responsive-design.md +37 -37
- package/templates/shared/rules/fec-source-driven-development.md +22 -22
- package/templates/shared/rules/fec-state-management.md +56 -56
- package/templates/shared/rules/fec-testing.md +64 -64
- package/templates/shared/rules/fec-typescript.md +75 -75
- package/templates/shared/rules/fec-vue.md +42 -42
- package/templates/shared/rules/fec-working-modes.md +34 -34
- 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
- package/skills/fec-drawio-studio/data/shape-index.json.gz +0 -0
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
# 坏味道到重构手法映射
|
|
2
|
+
|
|
3
|
+
候选手法只用于辅助选择。必须结合实际成因、前置条件、风险和“最小安全变化”判断,不能按关键词机械套用。
|
|
4
|
+
|
|
5
|
+
## SMELL-MYSTERIOUS-NAME — 神秘命名(Mysterious Name)
|
|
6
|
+
|
|
7
|
+
**主要/辅助候选**
|
|
8
|
+
- `RF-CHANGE-FUNCTION-DECLARATION`
|
|
9
|
+
- `RF-RENAME-VARIABLE`
|
|
10
|
+
- `RF-RENAME-FIELD`
|
|
11
|
+
|
|
12
|
+
**选择提示**
|
|
13
|
+
- 先确认“神秘命名”的真实成因,再从符合当前数据所有权、行为契约和前置条件的手法中选择最小安全变化。
|
|
14
|
+
|
|
15
|
+
## SMELL-DUPLICATED-CODE — 重复代码(Duplicated Code)
|
|
16
|
+
|
|
17
|
+
**主要/辅助候选**
|
|
18
|
+
- `RF-EXTRACT-FUNCTION`
|
|
19
|
+
- `RF-SLIDE-STATEMENTS`
|
|
20
|
+
- `RF-PULL-UP-METHOD`
|
|
21
|
+
|
|
22
|
+
**选择提示**
|
|
23
|
+
- 先确认“重复代码”的真实成因,再从符合当前数据所有权、行为契约和前置条件的手法中选择最小安全变化。
|
|
24
|
+
|
|
25
|
+
## SMELL-LONG-FUNCTION — 过长函数(Long Function)
|
|
26
|
+
|
|
27
|
+
**主要/辅助候选**
|
|
28
|
+
- `RF-EXTRACT-FUNCTION`
|
|
29
|
+
- `RF-REPLACE-TEMP-WITH-QUERY`
|
|
30
|
+
- `RF-INTRODUCE-PARAMETER-OBJECT`
|
|
31
|
+
- `RF-PRESERVE-WHOLE-OBJECT`
|
|
32
|
+
- `RF-REPLACE-FUNCTION-WITH-COMMAND`
|
|
33
|
+
- `RF-DECOMPOSE-CONDITIONAL`
|
|
34
|
+
- `RF-REPLACE-CONDITIONAL-WITH-POLYMORPHISM`
|
|
35
|
+
- `RF-SPLIT-LOOP`
|
|
36
|
+
|
|
37
|
+
**选择提示**
|
|
38
|
+
- 先确认“过长函数”的真实成因,再从符合当前数据所有权、行为契约和前置条件的手法中选择最小安全变化。
|
|
39
|
+
|
|
40
|
+
## SMELL-LONG-PARAMETER-LIST — 过长参数列表(Long Parameter List)
|
|
41
|
+
|
|
42
|
+
**主要/辅助候选**
|
|
43
|
+
- `RF-REPLACE-PARAMETER-WITH-QUERY`
|
|
44
|
+
- `RF-PRESERVE-WHOLE-OBJECT`
|
|
45
|
+
- `RF-INTRODUCE-PARAMETER-OBJECT`
|
|
46
|
+
- `RF-REMOVE-FLAG-ARGUMENT`
|
|
47
|
+
- `RF-COMBINE-FUNCTIONS-INTO-CLASS`
|
|
48
|
+
|
|
49
|
+
**选择提示**
|
|
50
|
+
- 先确认“过长参数列表”的真实成因,再从符合当前数据所有权、行为契约和前置条件的手法中选择最小安全变化。
|
|
51
|
+
|
|
52
|
+
## SMELL-GLOBAL-DATA — 全局数据(Global Data)
|
|
53
|
+
|
|
54
|
+
**主要/辅助候选**
|
|
55
|
+
- `RF-ENCAPSULATE-VARIABLE`
|
|
56
|
+
|
|
57
|
+
**选择提示**
|
|
58
|
+
- 先确认“全局数据”的真实成因,再从符合当前数据所有权、行为契约和前置条件的手法中选择最小安全变化。
|
|
59
|
+
|
|
60
|
+
## SMELL-MUTABLE-DATA — 可变数据(Mutable Data)
|
|
61
|
+
|
|
62
|
+
**主要/辅助候选**
|
|
63
|
+
- `RF-ENCAPSULATE-VARIABLE`
|
|
64
|
+
- `RF-SPLIT-VARIABLE`
|
|
65
|
+
- `RF-SLIDE-STATEMENTS`
|
|
66
|
+
- `RF-EXTRACT-FUNCTION`
|
|
67
|
+
- `RF-SEPARATE-QUERY-FROM-MODIFIER`
|
|
68
|
+
- `RF-REMOVE-SETTING-METHOD`
|
|
69
|
+
- `RF-REPLACE-DERIVED-VARIABLE-WITH-QUERY`
|
|
70
|
+
- `RF-COMBINE-FUNCTIONS-INTO-CLASS`
|
|
71
|
+
- `RF-COMBINE-FUNCTIONS-INTO-TRANSFORM`
|
|
72
|
+
- `RF-CHANGE-REFERENCE-TO-VALUE`
|
|
73
|
+
|
|
74
|
+
**选择提示**
|
|
75
|
+
- 先确认“可变数据”的真实成因,再从符合当前数据所有权、行为契约和前置条件的手法中选择最小安全变化。
|
|
76
|
+
|
|
77
|
+
## SMELL-DIVERGENT-CHANGE — 发散式变化(Divergent Change)
|
|
78
|
+
|
|
79
|
+
**主要/辅助候选**
|
|
80
|
+
- `RF-SPLIT-PHASE`
|
|
81
|
+
- `RF-MOVE-FUNCTION`
|
|
82
|
+
- `RF-EXTRACT-FUNCTION`
|
|
83
|
+
- `RF-EXTRACT-CLASS`
|
|
84
|
+
|
|
85
|
+
**选择提示**
|
|
86
|
+
- 先确认“发散式变化”的真实成因,再从符合当前数据所有权、行为契约和前置条件的手法中选择最小安全变化。
|
|
87
|
+
|
|
88
|
+
## SMELL-SHOTGUN-SURGERY — 霰弹式修改(Shotgun Surgery)
|
|
89
|
+
|
|
90
|
+
**主要/辅助候选**
|
|
91
|
+
- `RF-MOVE-FUNCTION`
|
|
92
|
+
- `RF-MOVE-FIELD`
|
|
93
|
+
- `RF-COMBINE-FUNCTIONS-INTO-CLASS`
|
|
94
|
+
- `RF-COMBINE-FUNCTIONS-INTO-TRANSFORM`
|
|
95
|
+
- `RF-SPLIT-PHASE`
|
|
96
|
+
- `RF-INLINE-FUNCTION`
|
|
97
|
+
- `RF-INLINE-CLASS`
|
|
98
|
+
|
|
99
|
+
**选择提示**
|
|
100
|
+
- 先确认“霰弹式修改”的真实成因,再从符合当前数据所有权、行为契约和前置条件的手法中选择最小安全变化。
|
|
101
|
+
|
|
102
|
+
## SMELL-FEATURE-ENVY — 依恋情结(Feature Envy)
|
|
103
|
+
|
|
104
|
+
**主要/辅助候选**
|
|
105
|
+
- `RF-MOVE-FUNCTION`
|
|
106
|
+
- `RF-EXTRACT-FUNCTION`
|
|
107
|
+
|
|
108
|
+
**选择提示**
|
|
109
|
+
- 先确认“依恋情结”的真实成因,再从符合当前数据所有权、行为契约和前置条件的手法中选择最小安全变化。
|
|
110
|
+
|
|
111
|
+
## SMELL-DATA-CLUMPS — 数据泥团(Data Clumps)
|
|
112
|
+
|
|
113
|
+
**主要/辅助候选**
|
|
114
|
+
- `RF-EXTRACT-CLASS`
|
|
115
|
+
- `RF-INTRODUCE-PARAMETER-OBJECT`
|
|
116
|
+
- `RF-PRESERVE-WHOLE-OBJECT`
|
|
117
|
+
|
|
118
|
+
**选择提示**
|
|
119
|
+
- 先确认“数据泥团”的真实成因,再从符合当前数据所有权、行为契约和前置条件的手法中选择最小安全变化。
|
|
120
|
+
|
|
121
|
+
## SMELL-PRIMITIVE-OBSESSION — 基本类型偏执(Primitive Obsession)
|
|
122
|
+
|
|
123
|
+
**主要/辅助候选**
|
|
124
|
+
- `RF-REPLACE-PRIMITIVE-WITH-OBJECT`
|
|
125
|
+
- `RF-REPLACE-TYPE-CODE-WITH-SUBCLASSES`
|
|
126
|
+
- `RF-REPLACE-CONDITIONAL-WITH-POLYMORPHISM`
|
|
127
|
+
- `RF-EXTRACT-CLASS`
|
|
128
|
+
- `RF-INTRODUCE-PARAMETER-OBJECT`
|
|
129
|
+
|
|
130
|
+
**选择提示**
|
|
131
|
+
- 先确认“基本类型偏执”的真实成因,再从符合当前数据所有权、行为契约和前置条件的手法中选择最小安全变化。
|
|
132
|
+
|
|
133
|
+
## SMELL-REPEATED-SWITCHES — 重复的 switch(Repeated Switches)
|
|
134
|
+
|
|
135
|
+
**主要/辅助候选**
|
|
136
|
+
- `RF-REPLACE-CONDITIONAL-WITH-POLYMORPHISM`
|
|
137
|
+
|
|
138
|
+
**选择提示**
|
|
139
|
+
- 先确认“重复的 switch”的真实成因,再从符合当前数据所有权、行为契约和前置条件的手法中选择最小安全变化。
|
|
140
|
+
|
|
141
|
+
## SMELL-LOOPS — 循环语句(Loops)
|
|
142
|
+
|
|
143
|
+
**主要/辅助候选**
|
|
144
|
+
- `RF-REPLACE-LOOP-WITH-PIPELINE`
|
|
145
|
+
|
|
146
|
+
**选择提示**
|
|
147
|
+
- 先确认“循环语句”的真实成因,再从符合当前数据所有权、行为契约和前置条件的手法中选择最小安全变化。
|
|
148
|
+
|
|
149
|
+
## SMELL-LAZY-ELEMENT — 冗赘的元素(Lazy Element)
|
|
150
|
+
|
|
151
|
+
**主要/辅助候选**
|
|
152
|
+
- `RF-INLINE-FUNCTION`
|
|
153
|
+
- `RF-INLINE-CLASS`
|
|
154
|
+
- `RF-COLLAPSE-HIERARCHY`
|
|
155
|
+
|
|
156
|
+
**选择提示**
|
|
157
|
+
- 先确认“冗赘的元素”的真实成因,再从符合当前数据所有权、行为契约和前置条件的手法中选择最小安全变化。
|
|
158
|
+
|
|
159
|
+
## SMELL-SPECULATIVE-GENERALITY — 夸夸其谈通用性(Speculative Generality)
|
|
160
|
+
|
|
161
|
+
**主要/辅助候选**
|
|
162
|
+
- `RF-COLLAPSE-HIERARCHY`
|
|
163
|
+
- `RF-INLINE-FUNCTION`
|
|
164
|
+
- `RF-INLINE-CLASS`
|
|
165
|
+
- `RF-CHANGE-FUNCTION-DECLARATION`
|
|
166
|
+
- `RF-REMOVE-DEAD-CODE`
|
|
167
|
+
|
|
168
|
+
**选择提示**
|
|
169
|
+
- 先确认“夸夸其谈通用性”的真实成因,再从符合当前数据所有权、行为契约和前置条件的手法中选择最小安全变化。
|
|
170
|
+
|
|
171
|
+
## SMELL-TEMPORARY-FIELD — 临时字段(Temporary Field)
|
|
172
|
+
|
|
173
|
+
**主要/辅助候选**
|
|
174
|
+
- `RF-EXTRACT-CLASS`
|
|
175
|
+
- `RF-MOVE-FUNCTION`
|
|
176
|
+
- `RF-INTRODUCE-SPECIAL-CASE`
|
|
177
|
+
|
|
178
|
+
**选择提示**
|
|
179
|
+
- 先确认“临时字段”的真实成因,再从符合当前数据所有权、行为契约和前置条件的手法中选择最小安全变化。
|
|
180
|
+
|
|
181
|
+
## SMELL-MESSAGE-CHAINS — 过长的消息链(Message Chains)
|
|
182
|
+
|
|
183
|
+
**主要/辅助候选**
|
|
184
|
+
- `RF-HIDE-DELEGATE`
|
|
185
|
+
- `RF-EXTRACT-FUNCTION`
|
|
186
|
+
- `RF-MOVE-FUNCTION`
|
|
187
|
+
|
|
188
|
+
**选择提示**
|
|
189
|
+
- 先确认“过长的消息链”的真实成因,再从符合当前数据所有权、行为契约和前置条件的手法中选择最小安全变化。
|
|
190
|
+
|
|
191
|
+
## SMELL-MIDDLE-MAN — 中间人(Middle Man)
|
|
192
|
+
|
|
193
|
+
**主要/辅助候选**
|
|
194
|
+
- `RF-REMOVE-MIDDLE-MAN`
|
|
195
|
+
- `RF-INLINE-FUNCTION`
|
|
196
|
+
- `RF-REPLACE-SUPERCLASS-WITH-DELEGATE`
|
|
197
|
+
- `RF-REPLACE-SUBCLASS-WITH-DELEGATE`
|
|
198
|
+
|
|
199
|
+
**选择提示**
|
|
200
|
+
- 先确认“中间人”的真实成因,再从符合当前数据所有权、行为契约和前置条件的手法中选择最小安全变化。
|
|
201
|
+
|
|
202
|
+
## SMELL-INSIDER-TRADING — 内幕交易(Insider Trading)
|
|
203
|
+
|
|
204
|
+
**主要/辅助候选**
|
|
205
|
+
- `RF-MOVE-FUNCTION`
|
|
206
|
+
- `RF-MOVE-FIELD`
|
|
207
|
+
- `RF-HIDE-DELEGATE`
|
|
208
|
+
- `RF-REPLACE-SUBCLASS-WITH-DELEGATE`
|
|
209
|
+
- `RF-REPLACE-SUPERCLASS-WITH-DELEGATE`
|
|
210
|
+
|
|
211
|
+
**选择提示**
|
|
212
|
+
- 先确认“内幕交易”的真实成因,再从符合当前数据所有权、行为契约和前置条件的手法中选择最小安全变化。
|
|
213
|
+
|
|
214
|
+
## SMELL-LARGE-CLASS — 过大的类(Large Class)
|
|
215
|
+
|
|
216
|
+
**主要/辅助候选**
|
|
217
|
+
- `RF-EXTRACT-CLASS`
|
|
218
|
+
- `RF-EXTRACT-SUPERCLASS`
|
|
219
|
+
- `RF-REPLACE-TYPE-CODE-WITH-SUBCLASSES`
|
|
220
|
+
|
|
221
|
+
**选择提示**
|
|
222
|
+
- 先确认“过大的类”的真实成因,再从符合当前数据所有权、行为契约和前置条件的手法中选择最小安全变化。
|
|
223
|
+
|
|
224
|
+
## SMELL-ALTERNATIVE-CLASSES-DIFFERENT-INTERFACES — 异曲同工的类(Alternative Classes with Different Interfaces)
|
|
225
|
+
|
|
226
|
+
**主要/辅助候选**
|
|
227
|
+
- `RF-CHANGE-FUNCTION-DECLARATION`
|
|
228
|
+
- `RF-MOVE-FUNCTION`
|
|
229
|
+
- `RF-EXTRACT-SUPERCLASS`
|
|
230
|
+
|
|
231
|
+
**选择提示**
|
|
232
|
+
- 先确认“异曲同工的类”的真实成因,再从符合当前数据所有权、行为契约和前置条件的手法中选择最小安全变化。
|
|
233
|
+
|
|
234
|
+
## SMELL-DATA-CLASS — 纯数据类(Data Class)
|
|
235
|
+
|
|
236
|
+
**主要/辅助候选**
|
|
237
|
+
- `RF-ENCAPSULATE-RECORD`
|
|
238
|
+
- `RF-REMOVE-SETTING-METHOD`
|
|
239
|
+
- `RF-MOVE-FUNCTION`
|
|
240
|
+
- `RF-EXTRACT-FUNCTION`
|
|
241
|
+
- `RF-SPLIT-PHASE`
|
|
242
|
+
|
|
243
|
+
**选择提示**
|
|
244
|
+
- 先确认“纯数据类”的真实成因,再从符合当前数据所有权、行为契约和前置条件的手法中选择最小安全变化。
|
|
245
|
+
|
|
246
|
+
## SMELL-REFUSED-BEQUEST — 被拒绝的遗赠(Refused Bequest)
|
|
247
|
+
|
|
248
|
+
**主要/辅助候选**
|
|
249
|
+
- `RF-PUSH-DOWN-METHOD`
|
|
250
|
+
- `RF-PUSH-DOWN-FIELD`
|
|
251
|
+
- `RF-REPLACE-SUBCLASS-WITH-DELEGATE`
|
|
252
|
+
- `RF-REPLACE-SUPERCLASS-WITH-DELEGATE`
|
|
253
|
+
|
|
254
|
+
**选择提示**
|
|
255
|
+
- 先确认“被拒绝的遗赠”的真实成因,再从符合当前数据所有权、行为契约和前置条件的手法中选择最小安全变化。
|
|
256
|
+
|
|
257
|
+
## SMELL-COMMENTS — 注释(Comments)
|
|
258
|
+
|
|
259
|
+
**主要/辅助候选**
|
|
260
|
+
- `RF-EXTRACT-FUNCTION`
|
|
261
|
+
- `RF-CHANGE-FUNCTION-DECLARATION`
|
|
262
|
+
- `RF-INTRODUCE-ASSERTION`
|
|
263
|
+
|
|
264
|
+
**选择提示**
|
|
265
|
+
- 先确认“注释”的真实成因,再从符合当前数据所有权、行为契约和前置条件的手法中选择最小安全变化。
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: fec-component-testing
|
|
3
|
+
description: 用于编写或审查靠近 UI 代码的前端单元、组件或轻量集成测试,包括 React Testing Library、Vue Test Utils、hooks/composables、props/emits、回调、可访问查询、user-event 交互、mock、loading/error/empty 状态和回归覆盖。若是测试分层规划、真实浏览器旅程或现有验证失败,优先选择对应测试或验证工作流;中文触发词包括 组件测试、组件单测、单元测试、轻量集成测试。
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# 组件测试
|
|
7
|
+
|
|
8
|
+
## 用途
|
|
9
|
+
|
|
10
|
+
用贴近代码和用户行为的测试验证纯逻辑、组件契约与轻量模块协作,减少重构和 UI 交互回归。
|
|
11
|
+
|
|
12
|
+
## 流程
|
|
13
|
+
|
|
14
|
+
### 1. 先确定测试层级
|
|
15
|
+
|
|
16
|
+
- 单元测试:纯函数、hooks/composables、utils、状态逻辑、schema。
|
|
17
|
+
- 组件测试:props/emits、回调、用户交互、loading/error/empty、mock 边界。
|
|
18
|
+
- 轻量集成测试:表单 + API mock + Router/Store/Provider 上下文。
|
|
19
|
+
|
|
20
|
+
跨页面真实浏览器流程分流到 E2E workflow;测试层选择不清楚时先做测试分层规划。
|
|
21
|
+
|
|
22
|
+
### 2. 优先按用户可感知行为测试
|
|
23
|
+
|
|
24
|
+
每个测试保持 Arrange / Act / Assert 清晰分段:准备数据和渲染、执行用户动作、断言用户可见结果或公开契约。
|
|
25
|
+
|
|
26
|
+
```tsx
|
|
27
|
+
import { render, screen } from "@testing-library/react";
|
|
28
|
+
import userEvent from "@testing-library/user-event";
|
|
29
|
+
import { SearchBox } from "./SearchBox";
|
|
30
|
+
|
|
31
|
+
test("submits the entered keyword", async () => {
|
|
32
|
+
const user = userEvent.setup();
|
|
33
|
+
const onSearch = vi.fn();
|
|
34
|
+
|
|
35
|
+
render(<SearchBox onSearch={onSearch} />);
|
|
36
|
+
|
|
37
|
+
await user.type(screen.getByRole("searchbox", { name: /keyword/i }), "orders");
|
|
38
|
+
await user.click(screen.getByRole("button", { name: /search/i }));
|
|
39
|
+
|
|
40
|
+
expect(onSearch).toHaveBeenCalledWith("orders");
|
|
41
|
+
});
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### 3. Vue 组件使用可访问查询或明确文本断言
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
import { mount } from "@vue/test-utils";
|
|
48
|
+
import UserMenu from "./UserMenu.vue";
|
|
49
|
+
|
|
50
|
+
test("emits logout when the logout item is clicked", async () => {
|
|
51
|
+
const wrapper = mount(UserMenu, {
|
|
52
|
+
props: { userName: "Ada" },
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
await wrapper.get('[data-testid="logout-button"]').trigger("click");
|
|
56
|
+
|
|
57
|
+
expect(wrapper.emitted("logout")).toHaveLength(1);
|
|
58
|
+
});
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
优先使用角色、标签和可见文本;仅在没有稳定语义时使用 `data-testid`。
|
|
62
|
+
|
|
63
|
+
### 4. 控制 mock 边界
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
vi.mock("../api/users", () => ({
|
|
67
|
+
fetchUsers: vi.fn(async () => [{ id: "1", name: "Ada" }]),
|
|
68
|
+
}));
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
- mock 网络、时间、路由和浏览器 API。
|
|
72
|
+
- 不 mock 被测组件的内部函数。
|
|
73
|
+
- 对设计系统基础组件只做轻量 mock,保留可访问行为。
|
|
74
|
+
- mock 数据应表达业务场景,不使用只有测试作者能理解的随意字符串。
|
|
75
|
+
- 共享 fixture 应保持可读,复杂对象用 builder 补默认值;每个测试只覆盖与场景相关的字段。
|
|
76
|
+
- mock 网络时优先模拟用户可见结果和错误形状,不复制后端实现细节。
|
|
77
|
+
|
|
78
|
+
### 5. 覆盖关键状态
|
|
79
|
+
|
|
80
|
+
每个复杂组件至少覆盖:
|
|
81
|
+
|
|
82
|
+
- 默认渲染。
|
|
83
|
+
- 用户交互和回调。
|
|
84
|
+
- loading / empty / error。
|
|
85
|
+
- 权限或禁用态。
|
|
86
|
+
- 键盘交互和焦点行为(适用时)。
|
|
87
|
+
|
|
88
|
+
### 6. 保持测试可维护
|
|
89
|
+
|
|
90
|
+
```ts
|
|
91
|
+
function setup() {
|
|
92
|
+
const user = userEvent.setup();
|
|
93
|
+
const onSubmit = vi.fn();
|
|
94
|
+
render(<ProfileForm onSubmit={onSubmit} />);
|
|
95
|
+
return { user, onSubmit };
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
将重复渲染逻辑放入 `setup`,但不要隐藏测试的核心操作和断言。
|
|
100
|
+
|
|
101
|
+
### 7. 回归测试先证明问题
|
|
102
|
+
|
|
103
|
+
- Bug 修复先写能复现失败的最小测试。
|
|
104
|
+
- 失败原因应指向用户行为或公开契约,而不是导入错误、测试环境或等待方式。
|
|
105
|
+
- 修复后保留回归测试,避免把验证只留在手工步骤里。
|
|
106
|
+
|
|
107
|
+
## 约束
|
|
108
|
+
|
|
109
|
+
- 避免测试实现细节,例如内部 state 名称、私有函数调用、DOM 层级快照。
|
|
110
|
+
- 不把 snapshot 作为交互组件的主要断言;它只能辅助检查稳定静态输出。
|
|
111
|
+
- 异步断言使用 `findBy*` 或 `waitFor`,不要用固定延迟。
|
|
112
|
+
- 测试名称应描述用户场景,而不是函数名。
|
|
113
|
+
- 组件测试不能替代 E2E;路由、真实浏览器兼容和跨页流程仍需 E2E。
|
|
114
|
+
- 不在测试里复制组件实现逻辑;否则测试会和错误实现一起通过。
|
|
115
|
+
- 不在测试间共享可变 fixture、全局 store 或 fake timer 状态;每个用例独立 setup 和 cleanup。
|
|
116
|
+
|
|
117
|
+
## 预期输出
|
|
118
|
+
|
|
119
|
+
产出与组件同目录或项目约定目录下的测试文件,覆盖核心交互、状态和回归场景。验证时运行项目现有 test 命令,确认失败信息能定位到用户行为或组件契约。
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: fec-data-fetching
|
|
3
|
+
description: 用于实现或审查前端服务端状态流程:类型化查询、请求缓存、失效、mutation、乐观更新、无限查询、预取、SSR hydration 或 API 层整合。不要用于本地 UI 状态或 Service Worker 缓存;中文触发词包括 数据获取、缓存、乐观更新。
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Server State 数据获取
|
|
7
|
+
|
|
8
|
+
## 用途
|
|
9
|
+
|
|
10
|
+
为前端 server state 建立清晰的数据获取、缓存、失效和提交边界,避免请求状态散落在页面组件中。
|
|
11
|
+
|
|
12
|
+
## 流程
|
|
13
|
+
|
|
14
|
+
1. 判断状态来源:来自服务端且需要缓存、去重、刷新、分页或 mutation 时使用请求缓存方案;纯本地 UI 状态用组件 state 或 store。
|
|
15
|
+
2. 先沿用项目已有数据获取库;新增依赖时 React/Vue/Solid/Svelte 可考虑 TanStack Query,也可沿用 SWR、Nuxt/Nitro 数据获取或项目封装。
|
|
16
|
+
3. 设计稳定 cache key/query key:结构包含实体、动作和所有影响结果的参数。
|
|
17
|
+
4. API 函数保持纯请求函数,数据 hook/composable 负责缓存、select、loading/error/empty 状态。
|
|
18
|
+
5. mutation 成功后 invalidation;需要即时反馈时使用 optimistic update 并在失败时回滚。
|
|
19
|
+
|
|
20
|
+
## React 快速开始
|
|
21
|
+
|
|
22
|
+
```tsx
|
|
23
|
+
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
24
|
+
|
|
25
|
+
export function UserList({ keyword }: { keyword: string }) {
|
|
26
|
+
const query = useQuery({
|
|
27
|
+
queryKey: ["users", "list", { keyword }],
|
|
28
|
+
queryFn: () => getUserList({ keyword, page: 1, pageSize: 20 }),
|
|
29
|
+
select: (response) => response.list,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
if (query.isLoading) return <Skeleton />;
|
|
33
|
+
if (query.isError) return <ErrorFallback onRetry={() => query.refetch()} />;
|
|
34
|
+
if (!query.data?.length) return <EmptyState />;
|
|
35
|
+
|
|
36
|
+
return query.data.map((user) => <UserRow key={user.id} user={user} />);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function useCreateUser() {
|
|
40
|
+
const queryClient = useQueryClient();
|
|
41
|
+
return useMutation({
|
|
42
|
+
mutationFn: createUser,
|
|
43
|
+
onSuccess: () => queryClient.invalidateQueries({ queryKey: ["users"] }),
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## 详细参考
|
|
49
|
+
|
|
50
|
+
涉及是否需要查询库、QueryClient 默认配置、Vue adapter、乐观更新、无限滚动查询、预取、SSR 水合和 API 层整合时,加载 [references/query-patterns.md](references/query-patterns.md)。
|
|
51
|
+
|
|
52
|
+
## 约束
|
|
53
|
+
|
|
54
|
+
- 相同数据必须复用相同 cache key/query key;参数缺失会造成缓存串读。
|
|
55
|
+
- `staleTime` 过长会显示旧数据,过短会造成频繁请求。
|
|
56
|
+
- 请求缓存库不管理本地 UI 状态;不要把 modal、输入框值放进 query cache。
|
|
57
|
+
- 乐观更新必须保存快照并在失败时回滚。
|
|
58
|
+
- SSR/SSG 场景必须使用框架支持的预取、水合或服务端数据边界。
|
|
59
|
+
|
|
60
|
+
## 预期输出
|
|
61
|
+
|
|
62
|
+
数据获取层具备 loading/error/empty/data 状态,重复请求自动去重,mutation 后缓存正确失效或回滚,API 层与 UI 层边界清晰。
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# Server State 数据获取模式
|
|
2
|
+
|
|
3
|
+
## 先判断是否需要查询库
|
|
4
|
+
|
|
5
|
+
- 简单静态请求、一次性提交或已有框架 loader 足够表达的页面,不必默认引入查询库。
|
|
6
|
+
- 需要跨组件缓存、去重、后台刷新、分页、乐观更新、预取或 SSR hydration 时,再使用 TanStack Query、SWR、Nuxt 数据获取或项目既有请求缓存方案。
|
|
7
|
+
- 查询库只管理 server state,不替代本地 UI 状态、表单状态、权限判断或 Service Worker 缓存。
|
|
8
|
+
|
|
9
|
+
## 选型参考
|
|
10
|
+
|
|
11
|
+
先沿用仓库已有请求层和缓存方案;新增依赖时再按框架与复杂度选择。
|
|
12
|
+
|
|
13
|
+
| 场景 | 候选方案 | 注意点 |
|
|
14
|
+
| --- | --- | --- |
|
|
15
|
+
| React server state | TanStack Query / SWR / 项目既有封装 | TanStack Query 适合 mutation、invalidation 和无限查询;SWR 适合轻量读取缓存。 |
|
|
16
|
+
| Vue server state | TanStack Query Vue adapter / VueUse / Nuxt `useFetch` / 项目既有封装 | 不要让 Vue 项目照搬 React-only hook 示例。 |
|
|
17
|
+
| Solid / Svelte / 跨框架 | TanStack Query 对应 adapter 或项目既有资源层 | cache key、staleTime、mutation 回滚原则保持一致。 |
|
|
18
|
+
| 简单页面请求 | 框架 loader、组件内轻量请求或 API composable | 仍要处理 loading/error/empty 和取消或过期响应。 |
|
|
19
|
+
| SSR / SSG | 框架预取、水合或服务端数据边界 | 确保服务端 key 与客户端 key 一致,避免重复请求和水合错配。 |
|
|
20
|
+
|
|
21
|
+
## 通用边界
|
|
22
|
+
|
|
23
|
+
- API 函数只负责请求、解析和错误归一化,不包含 UI toast、loading 或缓存逻辑。
|
|
24
|
+
- cache key/query key 必须包含所有影响响应的参数。
|
|
25
|
+
- mutation 成功后按实体或列表失效;乐观更新必须先保存快照,失败时回滚。
|
|
26
|
+
- 无限查询只处理数据分页;DOM 虚拟化由列表虚拟化流程处理。
|
|
27
|
+
- 预取要有明确用户路径或首屏收益,不为所有可能数据提前请求。
|
|
28
|
+
|
|
29
|
+
## QueryClient 默认配置
|
|
30
|
+
|
|
31
|
+
```tsx
|
|
32
|
+
const queryClient = new QueryClient({
|
|
33
|
+
defaultOptions: {
|
|
34
|
+
queries: {
|
|
35
|
+
staleTime: 5 * 60 * 1000,
|
|
36
|
+
gcTime: 30 * 60 * 1000,
|
|
37
|
+
retry: 2,
|
|
38
|
+
refetchOnWindowFocus: true,
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Query Key 设计
|
|
45
|
+
|
|
46
|
+
- 推荐:`["users", "list", { page, status }]`
|
|
47
|
+
- 详情:`["users", "detail", userId]`
|
|
48
|
+
- 所有影响请求结果的参数都必须进入 key。
|
|
49
|
+
|
|
50
|
+
## 乐观更新
|
|
51
|
+
|
|
52
|
+
```tsx
|
|
53
|
+
const mutation = useMutation({
|
|
54
|
+
mutationFn: () => api.likePost(postId),
|
|
55
|
+
onMutate: async () => {
|
|
56
|
+
await queryClient.cancelQueries({ queryKey: ["post", postId] });
|
|
57
|
+
const previousPost = queryClient.getQueryData(["post", postId]);
|
|
58
|
+
queryClient.setQueryData(["post", postId], (old: Post) => ({
|
|
59
|
+
...old,
|
|
60
|
+
likes: old.likes + 1,
|
|
61
|
+
liked: true,
|
|
62
|
+
}));
|
|
63
|
+
return { previousPost };
|
|
64
|
+
},
|
|
65
|
+
onError: (_error, _variables, context) => {
|
|
66
|
+
queryClient.setQueryData(["post", postId], context?.previousPost);
|
|
67
|
+
},
|
|
68
|
+
onSettled: () => {
|
|
69
|
+
queryClient.invalidateQueries({ queryKey: ["post", postId] });
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## 无限查询
|
|
75
|
+
|
|
76
|
+
```tsx
|
|
77
|
+
const feed = useInfiniteQuery({
|
|
78
|
+
queryKey: ["feed"],
|
|
79
|
+
queryFn: ({ pageParam = 1 }) => api.fetchFeed({ page: pageParam, limit: 20 }),
|
|
80
|
+
getNextPageParam: (lastPage, pages) => (lastPage.hasMore ? pages.length + 1 : undefined),
|
|
81
|
+
initialPageParam: 1,
|
|
82
|
+
});
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
虚拟列表场景将数据分页与 DOM 虚拟化分开设计。
|
|
86
|
+
|
|
87
|
+
## API 层整合
|
|
88
|
+
|
|
89
|
+
```ts
|
|
90
|
+
export async function getUserList(params: GetUserListParams): Promise<GetUserListResponse> {
|
|
91
|
+
return request.get("/api/users", { params });
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function useUsers(params: GetUserListParams) {
|
|
95
|
+
return useQuery({
|
|
96
|
+
queryKey: ["users", "list", params],
|
|
97
|
+
queryFn: () => getUserList(params),
|
|
98
|
+
select: (response) => response.list,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
API 函数不包含 UI toast、loading 或缓存逻辑。
|