@linyjs/plugin-docs 0.0.13
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/README.md +137 -0
- package/docs/api-reference/index.md +361 -0
- package/docs/best-practices/error-handling.md +462 -0
- package/docs/best-practices/naming-conventions.md +496 -0
- package/docs/best-practices/performance.md +532 -0
- package/docs/best-practices/security.md +620 -0
- package/docs/best-practices/service-definition.md +332 -0
- package/docs/faq.md +322 -0
- package/docs/getting-started/first-plugin.md +358 -0
- package/docs/getting-started/installation.md +244 -0
- package/docs/getting-started/quick-start.md +235 -0
- package/docs/guides/authentication.md +428 -0
- package/docs/guides/client-module.md +604 -0
- package/docs/guides/data-persistence.md +640 -0
- package/docs/guides/permissions.md +440 -0
- package/docs/guides/server-module.md +377 -0
- package/docs/guides/ui-slots.md +475 -0
- package/docs/migration/v0-to-v1.md +354 -0
- package/examples/analytics-plugin/README.md +416 -0
- package/examples/analytics-plugin/dist/client/index.d.ts +36 -0
- package/examples/analytics-plugin/dist/client/index.js +173 -0
- package/examples/analytics-plugin/dist/index.d.ts +64 -0
- package/examples/analytics-plugin/dist/index.js +72 -0
- package/examples/analytics-plugin/dist/server/index.d.ts +119 -0
- package/examples/analytics-plugin/dist/server/index.js +313 -0
- package/examples/analytics-plugin/package.json +28 -0
- package/examples/analytics-plugin/src/client/index.tsx +414 -0
- package/examples/analytics-plugin/src/index.ts +71 -0
- package/examples/analytics-plugin/src/server/index.ts +349 -0
- package/examples/analytics-plugin/tsconfig.json +21 -0
- package/examples/blog-plugin/README.md +319 -0
- package/examples/blog-plugin/dist/client/index.d.ts +22 -0
- package/examples/blog-plugin/dist/client/index.js +197 -0
- package/examples/blog-plugin/dist/server/index.d.ts +5 -0
- package/examples/blog-plugin/dist/server/index.js +220 -0
- package/examples/blog-plugin/package.json +24 -0
- package/examples/blog-plugin/src/client/index.tsx +409 -0
- package/examples/blog-plugin/src/server/index.ts +240 -0
- package/examples/blog-plugin/tsconfig.json +16 -0
- package/examples/hello-world/README.md +101 -0
- package/examples/hello-world/dist/client/index.d.ts +5 -0
- package/examples/hello-world/dist/client/index.js +80 -0
- package/examples/hello-world/dist/server/index.d.ts +5 -0
- package/examples/hello-world/dist/server/index.js +38 -0
- package/examples/hello-world/node_modules/.package-lock.json +61 -0
- package/examples/hello-world/node_modules/@linyjs/client-module-interface/HOOKS_USAGE.md +281 -0
- package/examples/hello-world/node_modules/@linyjs/client-module-interface/IMPLEMENTATION_SUMMARY.md +166 -0
- package/examples/hello-world/node_modules/@linyjs/client-module-interface/QUICK_REFERENCE.md +130 -0
- package/examples/hello-world/node_modules/@linyjs/client-module-interface/README.md +214 -0
- package/examples/hello-world/node_modules/@linyjs/client-module-interface/package.json +26 -0
- package/examples/hello-world/node_modules/@linyjs/client-module-interface/src/application.ts +50 -0
- package/examples/hello-world/node_modules/@linyjs/client-module-interface/src/comparison-example.tsx +229 -0
- package/examples/hello-world/node_modules/@linyjs/client-module-interface/src/di.ts +127 -0
- package/examples/hello-world/node_modules/@linyjs/client-module-interface/src/domain.ts +52 -0
- package/examples/hello-world/node_modules/@linyjs/client-module-interface/src/hooks-example.tsx +275 -0
- package/examples/hello-world/node_modules/@linyjs/client-module-interface/src/hooks.ts +175 -0
- package/examples/hello-world/node_modules/@linyjs/client-module-interface/src/index.ts +87 -0
- package/examples/hello-world/node_modules/@linyjs/client-module-interface/src/interfaces.ts +117 -0
- package/examples/hello-world/node_modules/@linyjs/client-module-interface/src/router.ts +49 -0
- package/examples/hello-world/node_modules/@linyjs/client-module-interface/tsconfig.json +10 -0
- package/examples/hello-world/node_modules/@linyjs/server-module-interface/package.json +21 -0
- package/examples/hello-world/node_modules/@linyjs/server-module-interface/src/application.ts +21 -0
- package/examples/hello-world/node_modules/@linyjs/server-module-interface/src/di.ts +127 -0
- package/examples/hello-world/node_modules/@linyjs/server-module-interface/src/domain.ts +75 -0
- package/examples/hello-world/node_modules/@linyjs/server-module-interface/src/index.ts +55 -0
- package/examples/hello-world/node_modules/@linyjs/server-module-interface/src/interfaces.ts +58 -0
- package/examples/hello-world/node_modules/@linyjs/server-module-interface/tsconfig.json +8 -0
- package/examples/hello-world/node_modules/@types/react/LICENSE +21 -0
- package/examples/hello-world/node_modules/@types/react/README.md +15 -0
- package/examples/hello-world/node_modules/@types/react/canary.d.ts +129 -0
- package/examples/hello-world/node_modules/@types/react/compiler-runtime.d.ts +4 -0
- package/examples/hello-world/node_modules/@types/react/experimental.d.ts +184 -0
- package/examples/hello-world/node_modules/@types/react/global.d.ts +166 -0
- package/examples/hello-world/node_modules/@types/react/index.d.ts +4369 -0
- package/examples/hello-world/node_modules/@types/react/jsx-dev-runtime.d.ts +33 -0
- package/examples/hello-world/node_modules/@types/react/jsx-runtime.d.ts +24 -0
- package/examples/hello-world/node_modules/@types/react/package.json +210 -0
- package/examples/hello-world/node_modules/@types/react/ts5.0/canary.d.ts +129 -0
- package/examples/hello-world/node_modules/@types/react/ts5.0/experimental.d.ts +184 -0
- package/examples/hello-world/node_modules/@types/react/ts5.0/global.d.ts +166 -0
- package/examples/hello-world/node_modules/@types/react/ts5.0/index.d.ts +4356 -0
- package/examples/hello-world/node_modules/@types/react/ts5.0/jsx-dev-runtime.d.ts +33 -0
- package/examples/hello-world/node_modules/@types/react/ts5.0/jsx-runtime.d.ts +24 -0
- package/examples/hello-world/node_modules/csstype/LICENSE +19 -0
- package/examples/hello-world/node_modules/csstype/README.md +291 -0
- package/examples/hello-world/node_modules/csstype/index.d.ts +22569 -0
- package/examples/hello-world/node_modules/csstype/index.js.flow +6863 -0
- package/examples/hello-world/node_modules/csstype/package.json +70 -0
- package/examples/hello-world/node_modules/react/LICENSE +21 -0
- package/examples/hello-world/node_modules/react/README.md +37 -0
- package/examples/hello-world/node_modules/react/cjs/react-compiler-runtime.development.js +24 -0
- package/examples/hello-world/node_modules/react/cjs/react-compiler-runtime.production.js +16 -0
- package/examples/hello-world/node_modules/react/cjs/react-compiler-runtime.profiling.js +16 -0
- package/examples/hello-world/node_modules/react/cjs/react-jsx-dev-runtime.development.js +338 -0
- package/examples/hello-world/node_modules/react/cjs/react-jsx-dev-runtime.production.js +14 -0
- package/examples/hello-world/node_modules/react/cjs/react-jsx-dev-runtime.profiling.js +14 -0
- package/examples/hello-world/node_modules/react/cjs/react-jsx-dev-runtime.react-server.development.js +370 -0
- package/examples/hello-world/node_modules/react/cjs/react-jsx-dev-runtime.react-server.production.js +40 -0
- package/examples/hello-world/node_modules/react/cjs/react-jsx-runtime.development.js +352 -0
- package/examples/hello-world/node_modules/react/cjs/react-jsx-runtime.production.js +34 -0
- package/examples/hello-world/node_modules/react/cjs/react-jsx-runtime.profiling.js +34 -0
- package/examples/hello-world/node_modules/react/cjs/react-jsx-runtime.react-server.development.js +370 -0
- package/examples/hello-world/node_modules/react/cjs/react-jsx-runtime.react-server.production.js +40 -0
- package/examples/hello-world/node_modules/react/cjs/react.development.js +1284 -0
- package/examples/hello-world/node_modules/react/cjs/react.production.js +542 -0
- package/examples/hello-world/node_modules/react/cjs/react.react-server.development.js +848 -0
- package/examples/hello-world/node_modules/react/cjs/react.react-server.production.js +423 -0
- package/examples/hello-world/node_modules/react/compiler-runtime.js +14 -0
- package/examples/hello-world/node_modules/react/index.js +7 -0
- package/examples/hello-world/node_modules/react/jsx-dev-runtime.js +7 -0
- package/examples/hello-world/node_modules/react/jsx-dev-runtime.react-server.js +7 -0
- package/examples/hello-world/node_modules/react/jsx-runtime.js +7 -0
- package/examples/hello-world/node_modules/react/jsx-runtime.react-server.js +7 -0
- package/examples/hello-world/node_modules/react/package.json +51 -0
- package/examples/hello-world/node_modules/react/react.react-server.js +7 -0
- package/examples/hello-world/node_modules/typescript/LICENSE.txt +55 -0
- package/examples/hello-world/node_modules/typescript/README.md +50 -0
- package/examples/hello-world/node_modules/typescript/SECURITY.md +41 -0
- package/examples/hello-world/node_modules/typescript/ThirdPartyNoticeText.txt +193 -0
- package/examples/hello-world/node_modules/typescript/bin/tsc +2 -0
- package/examples/hello-world/node_modules/typescript/bin/tsserver +2 -0
- package/examples/hello-world/node_modules/typescript/lib/_tsc.js +133818 -0
- package/examples/hello-world/node_modules/typescript/lib/_tsserver.js +659 -0
- package/examples/hello-world/node_modules/typescript/lib/_typingsInstaller.js +222 -0
- package/examples/hello-world/node_modules/typescript/lib/cs/diagnosticMessages.generated.json +2122 -0
- package/examples/hello-world/node_modules/typescript/lib/de/diagnosticMessages.generated.json +2122 -0
- package/examples/hello-world/node_modules/typescript/lib/es/diagnosticMessages.generated.json +2122 -0
- package/examples/hello-world/node_modules/typescript/lib/fr/diagnosticMessages.generated.json +2122 -0
- package/examples/hello-world/node_modules/typescript/lib/it/diagnosticMessages.generated.json +2122 -0
- package/examples/hello-world/node_modules/typescript/lib/ja/diagnosticMessages.generated.json +2122 -0
- package/examples/hello-world/node_modules/typescript/lib/ko/diagnosticMessages.generated.json +2122 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.d.ts +22 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.decorators.d.ts +384 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.decorators.legacy.d.ts +22 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.dom.asynciterable.d.ts +41 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.dom.d.ts +39429 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.dom.iterable.d.ts +571 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2015.collection.d.ts +147 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2015.core.d.ts +597 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2015.d.ts +28 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2015.generator.d.ts +77 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2015.iterable.d.ts +605 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2015.promise.d.ts +81 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2015.proxy.d.ts +128 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2015.reflect.d.ts +144 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2015.symbol.d.ts +46 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts +326 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2016.array.include.d.ts +116 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2016.d.ts +21 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2016.full.d.ts +23 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2016.intl.d.ts +31 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2017.arraybuffer.d.ts +21 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2017.d.ts +26 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2017.date.d.ts +31 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2017.full.d.ts +23 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2017.intl.d.ts +44 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2017.object.d.ts +49 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts +135 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2017.string.d.ts +45 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2017.typedarrays.d.ts +53 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts +77 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2018.asynciterable.d.ts +53 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2018.d.ts +24 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2018.full.d.ts +24 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2018.intl.d.ts +83 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2018.promise.d.ts +30 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2018.regexp.d.ts +37 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2019.array.d.ts +79 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2019.d.ts +24 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2019.full.d.ts +24 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2019.intl.d.ts +23 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2019.object.d.ts +33 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2019.string.d.ts +37 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2019.symbol.d.ts +24 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2020.bigint.d.ts +765 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2020.d.ts +27 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2020.date.d.ts +42 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2020.full.d.ts +24 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2020.intl.d.ts +474 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2020.number.d.ts +28 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2020.promise.d.ts +47 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts +99 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2020.string.d.ts +44 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts +41 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2021.d.ts +23 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2021.full.d.ts +24 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2021.intl.d.ts +166 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2021.promise.d.ts +48 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2021.string.d.ts +33 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2021.weakref.d.ts +78 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2022.array.d.ts +121 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2022.d.ts +25 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2022.error.d.ts +75 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2022.full.d.ts +24 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2022.intl.d.ts +145 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2022.object.d.ts +26 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2022.regexp.d.ts +39 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2022.string.d.ts +25 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2023.array.d.ts +924 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2023.collection.d.ts +21 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2023.d.ts +22 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2023.full.d.ts +24 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2023.intl.d.ts +56 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2024.arraybuffer.d.ts +65 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2024.collection.d.ts +29 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2024.d.ts +26 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2024.full.d.ts +24 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2024.object.d.ts +29 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2024.promise.d.ts +35 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2024.regexp.d.ts +25 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2024.sharedmemory.d.ts +68 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2024.string.d.ts +29 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es5.d.ts +4601 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es6.d.ts +23 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.esnext.array.d.ts +35 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.esnext.collection.d.ts +96 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.esnext.d.ts +29 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.esnext.decorators.d.ts +28 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.esnext.disposable.d.ts +193 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.esnext.error.d.ts +24 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.esnext.float16.d.ts +445 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.esnext.full.d.ts +24 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.esnext.intl.d.ts +21 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.esnext.iterator.d.ts +148 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.esnext.promise.d.ts +34 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.esnext.sharedmemory.d.ts +25 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.scripthost.d.ts +322 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.webworker.asynciterable.d.ts +41 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.webworker.d.ts +13150 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.webworker.importscripts.d.ts +23 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.webworker.iterable.d.ts +340 -0
- package/examples/hello-world/node_modules/typescript/lib/pl/diagnosticMessages.generated.json +2122 -0
- package/examples/hello-world/node_modules/typescript/lib/pt-br/diagnosticMessages.generated.json +2122 -0
- package/examples/hello-world/node_modules/typescript/lib/ru/diagnosticMessages.generated.json +2122 -0
- package/examples/hello-world/node_modules/typescript/lib/tr/diagnosticMessages.generated.json +2122 -0
- package/examples/hello-world/node_modules/typescript/lib/tsc.js +8 -0
- package/examples/hello-world/node_modules/typescript/lib/tsserver.js +8 -0
- package/examples/hello-world/node_modules/typescript/lib/tsserverlibrary.d.ts +17 -0
- package/examples/hello-world/node_modules/typescript/lib/tsserverlibrary.js +21 -0
- package/examples/hello-world/node_modules/typescript/lib/typesMap.json +497 -0
- package/examples/hello-world/node_modules/typescript/lib/typescript.d.ts +11437 -0
- package/examples/hello-world/node_modules/typescript/lib/typescript.js +200276 -0
- package/examples/hello-world/node_modules/typescript/lib/typingsInstaller.js +8 -0
- package/examples/hello-world/node_modules/typescript/lib/watchGuard.js +53 -0
- package/examples/hello-world/node_modules/typescript/lib/zh-cn/diagnosticMessages.generated.json +2122 -0
- package/examples/hello-world/node_modules/typescript/lib/zh-tw/diagnosticMessages.generated.json +2122 -0
- package/examples/hello-world/node_modules/typescript/package.json +120 -0
- package/examples/hello-world/package-lock.json +74 -0
- package/examples/hello-world/package.json +23 -0
- package/examples/hello-world/src/client/index.tsx +110 -0
- package/examples/hello-world/src/server/index.ts +42 -0
- package/examples/hello-world/tsconfig.json +16 -0
- package/package.json +46 -0
- package/src/cli.ts +321 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# Hello World Example Plugin
|
|
2
|
+
|
|
3
|
+
最简单的 linyjs 插件示例,展示基本的 API 和页面开发。
|
|
4
|
+
|
|
5
|
+
## 📋 功能
|
|
6
|
+
|
|
7
|
+
- ✅ 服务端: `/api/hello` API 端点
|
|
8
|
+
- ✅ 客户端: `/hello` 页面,可输入名字并显示问候语
|
|
9
|
+
- ✅ 交互式 UI: 实时更新问候消息
|
|
10
|
+
|
|
11
|
+
## 🚀 快速开始
|
|
12
|
+
|
|
13
|
+
### 1. 安装依赖
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### 2. 开发模式
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm run dev
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
这会在文件更改时自动重新编译。
|
|
26
|
+
|
|
27
|
+
### 3. 构建插件
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npm run build
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
编译后的文件将输出到 `dist/` 目录。
|
|
34
|
+
|
|
35
|
+
### 4. 打包为 .mpk
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
npx @linyjs/cli pack
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
生成 `hello-world-example.mpk` 文件。
|
|
42
|
+
|
|
43
|
+
### 5. 测试插件
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
# 复制插件到 extensions 目录
|
|
47
|
+
cp hello-world-example.mpk /path/to/linyjs/packages/ssr/extensions/
|
|
48
|
+
|
|
49
|
+
# 启动 SSR 服务器
|
|
50
|
+
cd /path/to/linyjs/packages/ssr
|
|
51
|
+
npx tsx src/demo/dev-server-with-pkg.tsx
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
访问 `http://localhost:3000/hello` 查看效果!
|
|
55
|
+
|
|
56
|
+
## 📁 项目结构
|
|
57
|
+
|
|
58
|
+
```
|
|
59
|
+
hello-world/
|
|
60
|
+
├── package.json # NPM 配置
|
|
61
|
+
├── tsconfig.json # TypeScript 配置
|
|
62
|
+
└── src/
|
|
63
|
+
├── server/
|
|
64
|
+
│ └── index.ts # 服务端代码 (API)
|
|
65
|
+
└── client/
|
|
66
|
+
└── index.tsx # 客户端代码 (React 页面)
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## 💡 代码说明
|
|
70
|
+
|
|
71
|
+
### 服务端 (`src/server/index.ts`)
|
|
72
|
+
|
|
73
|
+
定义了一个简单的 GET API:
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
{
|
|
77
|
+
method: 'GET',
|
|
78
|
+
path: '/api/hello',
|
|
79
|
+
handler: async (params, ctx) => {
|
|
80
|
+
return { message: `Hello, ${name}!` };
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### 客户端 (`src/client/index.tsx`)
|
|
86
|
+
|
|
87
|
+
创建了一个 React 页面组件:
|
|
88
|
+
|
|
89
|
+
- 使用 `useState` 管理状态
|
|
90
|
+
- 使用 `useEffect` 调用 API
|
|
91
|
+
- 提供输入框让用户输入名字
|
|
92
|
+
|
|
93
|
+
## 🔗 相关文档
|
|
94
|
+
|
|
95
|
+
- [Plugin Development Guide](node_modules/@linyjs/plugin-docs/docs/getting-started/quick-start.md)
|
|
96
|
+
- [Server Module Guide](node_modules/@linyjs/plugin-docs/docs/guides/server-module.md)
|
|
97
|
+
- [Client Module Guide](node_modules/@linyjs/plugin-docs/docs/guides/client-module.md)
|
|
98
|
+
|
|
99
|
+
## 📝 许可证
|
|
100
|
+
|
|
101
|
+
MIT
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
/**
|
|
4
|
+
* Hello World 页面组件
|
|
5
|
+
*/
|
|
6
|
+
function HelloPage() {
|
|
7
|
+
const [message, setMessage] = React.useState('Loading...');
|
|
8
|
+
const [name, setName] = React.useState('World');
|
|
9
|
+
// 调用 API 获取问候消息
|
|
10
|
+
React.useEffect(() => {
|
|
11
|
+
fetch(`/api/hello?name=${encodeURIComponent(name)}`)
|
|
12
|
+
.then(res => res.json())
|
|
13
|
+
.then(data => {
|
|
14
|
+
setMessage(data.message);
|
|
15
|
+
})
|
|
16
|
+
.catch(err => {
|
|
17
|
+
console.error('Failed to fetch:', err);
|
|
18
|
+
setMessage('Error loading message');
|
|
19
|
+
});
|
|
20
|
+
}, [name]);
|
|
21
|
+
return (_jsxs("div", { style: {
|
|
22
|
+
padding: '40px',
|
|
23
|
+
maxWidth: '600px',
|
|
24
|
+
margin: '0 auto',
|
|
25
|
+
fontFamily: 'Arial, sans-serif'
|
|
26
|
+
}, children: [_jsx("h1", { style: { color: '#333' }, children: "\uD83D\uDC4B Hello World Plugin" }), _jsx("div", { style: {
|
|
27
|
+
marginTop: '20px',
|
|
28
|
+
padding: '20px',
|
|
29
|
+
backgroundColor: '#f5f5f5',
|
|
30
|
+
borderRadius: '8px'
|
|
31
|
+
}, children: _jsx("p", { style: { fontSize: '18px', color: '#666' }, children: message }) }), _jsxs("div", { style: { marginTop: '20px' }, children: [_jsx("label", { style: { display: 'block', marginBottom: '8px', color: '#666' }, children: "Enter your name:" }), _jsx("input", { type: "text", value: name, onChange: (e) => setName(e.target.value), placeholder: "Enter your name", style: {
|
|
32
|
+
padding: '10px',
|
|
33
|
+
fontSize: '16px',
|
|
34
|
+
border: '1px solid #ddd',
|
|
35
|
+
borderRadius: '4px',
|
|
36
|
+
width: '100%',
|
|
37
|
+
boxSizing: 'border-box'
|
|
38
|
+
} })] }), _jsxs("div", { style: {
|
|
39
|
+
marginTop: '30px',
|
|
40
|
+
padding: '15px',
|
|
41
|
+
backgroundColor: '#e3f2fd',
|
|
42
|
+
borderRadius: '4px',
|
|
43
|
+
fontSize: '14px',
|
|
44
|
+
color: '#1976d2'
|
|
45
|
+
}, children: [_jsx("strong", { children: "\uD83D\uDCA1 Tip:" }), " This is a minimal linyjs plugin example. Try modifying the code in ", _jsx("code", { children: "src/server/index.ts" }), " and ", _jsx("code", { children: "src/client/index.tsx" }), "."] })] }));
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* 路由服务
|
|
49
|
+
*/
|
|
50
|
+
class HelloRouteService {
|
|
51
|
+
constructor() {
|
|
52
|
+
this.basePath = '/hello';
|
|
53
|
+
}
|
|
54
|
+
getRoutes() {
|
|
55
|
+
return [
|
|
56
|
+
{
|
|
57
|
+
path: '/',
|
|
58
|
+
component: HelloPage,
|
|
59
|
+
key: 'hello-page',
|
|
60
|
+
meta: {
|
|
61
|
+
title: 'Hello World',
|
|
62
|
+
requiresAuth: false
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
];
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* 客户端模块定义
|
|
70
|
+
*/
|
|
71
|
+
export const helloClientModule = {
|
|
72
|
+
name: 'helloClient',
|
|
73
|
+
serviceDefs: [
|
|
74
|
+
{
|
|
75
|
+
serviceTag: 'helloRoute',
|
|
76
|
+
serviceImpl: HelloRouteService,
|
|
77
|
+
meta: { usageType: 'route' }
|
|
78
|
+
}
|
|
79
|
+
]
|
|
80
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hello World 控制器
|
|
3
|
+
* 提供一个简单的 API 端点返回问候消息
|
|
4
|
+
*/
|
|
5
|
+
class HelloController {
|
|
6
|
+
getRoutes() {
|
|
7
|
+
return [
|
|
8
|
+
{
|
|
9
|
+
method: 'GET',
|
|
10
|
+
path: '/api/hello',
|
|
11
|
+
middlewares: [],
|
|
12
|
+
responseType: 'json',
|
|
13
|
+
handler: async (params, ctx) => {
|
|
14
|
+
// 获取查询参数(如果有)
|
|
15
|
+
const name = params.query?.name || 'World';
|
|
16
|
+
return {
|
|
17
|
+
message: `Hello, ${name}!`,
|
|
18
|
+
timestamp: new Date().toISOString(),
|
|
19
|
+
plugin: 'hello-world-example'
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
];
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* 服务端模块定义
|
|
28
|
+
*/
|
|
29
|
+
export const helloServerModule = {
|
|
30
|
+
name: 'helloServer',
|
|
31
|
+
serviceDefs: [
|
|
32
|
+
{
|
|
33
|
+
serviceTag: 'helloController',
|
|
34
|
+
serviceImpl: HelloController,
|
|
35
|
+
meta: { usageType: 'controller' }
|
|
36
|
+
}
|
|
37
|
+
]
|
|
38
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@linyjs/example-hello-world",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"lockfileVersion": 3,
|
|
5
|
+
"requires": true,
|
|
6
|
+
"packages": {
|
|
7
|
+
"node_modules/@linyjs/client-module-interface": {
|
|
8
|
+
"version": "0.0.1",
|
|
9
|
+
"resolved": "https://registry.npmmirror.com/@linyjs/client-module-interface/-/client-module-interface-0.0.1.tgz",
|
|
10
|
+
"integrity": "sha512-StKnCtzKq+ZHoApWQqOHEPrlMq0VqZ5C4ZYB9t27LNOzep8j4qwMqNnEP99S/KC4m/9rVGJlnJw0O+Kf2NVYYg==",
|
|
11
|
+
"peerDependencies": {
|
|
12
|
+
"react": "^19.0.0"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"node_modules/@linyjs/server-module-interface": {
|
|
16
|
+
"version": "0.0.1",
|
|
17
|
+
"resolved": "https://registry.npmmirror.com/@linyjs/server-module-interface/-/server-module-interface-0.0.1.tgz",
|
|
18
|
+
"integrity": "sha512-jrwW0uI8F7TCwGMvGVW4EkxcdDaXTIZhDS5tcahTiA9pqsNDMXULcy0oPrmaPMp6uaqdt3rSTp0ybThggym/RQ=="
|
|
19
|
+
},
|
|
20
|
+
"node_modules/@types/react": {
|
|
21
|
+
"version": "19.2.17",
|
|
22
|
+
"resolved": "https://registry.npmmirror.com/@types/react/-/react-19.2.17.tgz",
|
|
23
|
+
"integrity": "sha512-MXfmqaVPEVgkBT/aY0aGCkRWWtByiYQXo3xdQ8r5RzuFrPiRn8Gar2tQdXSUQ2GKV3bkXckek89V8wQBY2Q/Aw==",
|
|
24
|
+
"dev": true,
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"csstype": "^3.2.2"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"node_modules/csstype": {
|
|
31
|
+
"version": "3.2.3",
|
|
32
|
+
"resolved": "https://registry.npmmirror.com/csstype/-/csstype-3.2.3.tgz",
|
|
33
|
+
"integrity": "sha512-z1HGKcYy2xA8AGQfwrn0PAy+PB7X/GSj3UVJW9qKyn43xWa+gl5nXmU4qqLMRzWVLFC8KusUX8T/0kCiOYpAIQ==",
|
|
34
|
+
"dev": true,
|
|
35
|
+
"license": "MIT"
|
|
36
|
+
},
|
|
37
|
+
"node_modules/react": {
|
|
38
|
+
"version": "19.2.7",
|
|
39
|
+
"resolved": "https://registry.npmmirror.com/react/-/react-19.2.7.tgz",
|
|
40
|
+
"integrity": "sha512-HNe9WslTbXmFK8o8cmwgAeJFSBvt1bPdHCVKtaaV+WlAN36mpT4hcRpwbf3fY56ar2oIXzsBpOAiIRHAdY0OlQ==",
|
|
41
|
+
"license": "MIT",
|
|
42
|
+
"engines": {
|
|
43
|
+
"node": ">=0.10.0"
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"node_modules/typescript": {
|
|
47
|
+
"version": "5.9.3",
|
|
48
|
+
"resolved": "https://registry.npmmirror.com/typescript/-/typescript-5.9.3.tgz",
|
|
49
|
+
"integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==",
|
|
50
|
+
"dev": true,
|
|
51
|
+
"license": "Apache-2.0",
|
|
52
|
+
"bin": {
|
|
53
|
+
"tsc": "bin/tsc",
|
|
54
|
+
"tsserver": "bin/tsserver"
|
|
55
|
+
},
|
|
56
|
+
"engines": {
|
|
57
|
+
"node": ">=14.17"
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
# 资源消费 Hooks 使用指南
|
|
2
|
+
|
|
3
|
+
本文档展示如何在模块中使用 `useClientComponent`、`useClientHook` 和 `useClientService`。
|
|
4
|
+
|
|
5
|
+
## 快速开始
|
|
6
|
+
|
|
7
|
+
### 1. 导入 Hooks
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
import {
|
|
11
|
+
useClientComponent,
|
|
12
|
+
useClientHook,
|
|
13
|
+
useClientService
|
|
14
|
+
} from '@ling/client-module-interface'
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
### 2. 基本用法
|
|
18
|
+
|
|
19
|
+
#### 使用组件
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
function MyPage() {
|
|
23
|
+
// 跨模块引用组件
|
|
24
|
+
const Avatar = useClientComponent('userModule.userComponents.Avatar')
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<div>
|
|
28
|
+
{Avatar && <Avatar userId="123" size="large" />}
|
|
29
|
+
</div>
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
#### 使用 Hook
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
function AuthStatus() {
|
|
38
|
+
// 定义 Hook 类型
|
|
39
|
+
type UseAuthHook = () => {
|
|
40
|
+
isAuthenticated: boolean
|
|
41
|
+
user: { id: string; name: string } | null
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// 引用 Hook
|
|
45
|
+
const useAuth = useClientHook<UseAuthHook>('authModule.authHooks.useAuth')
|
|
46
|
+
|
|
47
|
+
// 调用 Hook
|
|
48
|
+
const authState = useAuth ? useAuth() : null
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<div>
|
|
52
|
+
{authState?.isAuthenticated ? '已登录' : '未登录'}
|
|
53
|
+
</div>
|
|
54
|
+
)
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
#### 使用服务
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
interface IUserService {
|
|
62
|
+
getUser(id: string): Promise<User>
|
|
63
|
+
updateUser(id: string, data: Partial<User>): Promise<void>
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function UserManagement() {
|
|
67
|
+
// 引用服务
|
|
68
|
+
const userService = useClientService<IUserService>('userModule.userService')
|
|
69
|
+
|
|
70
|
+
const handleLoadUser = async () => {
|
|
71
|
+
if (userService) {
|
|
72
|
+
const user = await userService.getUser('123')
|
|
73
|
+
console.log(user)
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return <button onClick={handleLoadUser}>加载用户</button>
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## 高级用法
|
|
82
|
+
|
|
83
|
+
### 1. 混合使用多种资源
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
function UserProfile() {
|
|
87
|
+
// 引用多个组件
|
|
88
|
+
const Avatar = useClientComponent('userModule.userComponents.Avatar')
|
|
89
|
+
const Card = useClientComponent('uiModule.uiComponents.Card')
|
|
90
|
+
const Button = useClientComponent('uiModule.uiComponents.Button')
|
|
91
|
+
|
|
92
|
+
// 引用 Hook
|
|
93
|
+
type UseAuthHook = () => { isAuthenticated: boolean; user: any }
|
|
94
|
+
const useAuth = useClientHook<UseAuthHook>('authModule.authHooks.useAuth')
|
|
95
|
+
const authState = useAuth ? useAuth() : null
|
|
96
|
+
|
|
97
|
+
// 引用服务
|
|
98
|
+
const userService = useClientService<IUserService>('userModule.userService')
|
|
99
|
+
|
|
100
|
+
const handleUpdate = async () => {
|
|
101
|
+
if (userService && authState?.user) {
|
|
102
|
+
await userService.updateUser(authState.user.id, { name: 'New Name' })
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return (
|
|
107
|
+
<div>
|
|
108
|
+
{Card && (
|
|
109
|
+
<Card title="用户信息">
|
|
110
|
+
{Avatar && authState?.user && (
|
|
111
|
+
<Avatar userId={authState.user.id} />
|
|
112
|
+
)}
|
|
113
|
+
|
|
114
|
+
<p>{authState?.user?.name}</p>
|
|
115
|
+
|
|
116
|
+
{Button && (
|
|
117
|
+
<Button text="更新" onClick={handleUpdate} />
|
|
118
|
+
)}
|
|
119
|
+
</Card>
|
|
120
|
+
)}
|
|
121
|
+
</div>
|
|
122
|
+
)
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### 2. 条件渲染
|
|
127
|
+
|
|
128
|
+
```typescript
|
|
129
|
+
function ConditionalExample() {
|
|
130
|
+
const Avatar = useClientComponent('userModule.userComponents.Avatar')
|
|
131
|
+
|
|
132
|
+
// 如果组件不存在,显示降级 UI
|
|
133
|
+
if (!Avatar) {
|
|
134
|
+
return <div>头像组件加载中...</div>
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return <Avatar userId="123" />
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### 3. 错误处理
|
|
142
|
+
|
|
143
|
+
```typescript
|
|
144
|
+
function ErrorHandlingExample() {
|
|
145
|
+
const userService = useClientService<IUserService>('userModule.userService')
|
|
146
|
+
|
|
147
|
+
const handleAction = async () => {
|
|
148
|
+
if (!userService) {
|
|
149
|
+
console.error('用户服务未找到')
|
|
150
|
+
return
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
try {
|
|
154
|
+
const user = await userService.getUser('123')
|
|
155
|
+
console.log('用户加载成功:', user)
|
|
156
|
+
} catch (error) {
|
|
157
|
+
console.error('加载用户失败:', error)
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return <button onClick={handleAction}>加载用户</button>
|
|
162
|
+
}
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
## 最佳实践
|
|
166
|
+
|
|
167
|
+
### ✅ 推荐做法
|
|
168
|
+
|
|
169
|
+
1. **使用泛型提供类型约束**
|
|
170
|
+
```typescript
|
|
171
|
+
const userService = useClientService<IUserService>('...')
|
|
172
|
+
const useAuth = useClientHook<UseAuthHook>('...')
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
2. **进行空值检查**
|
|
176
|
+
```typescript
|
|
177
|
+
const Avatar = useClientComponent('...')
|
|
178
|
+
if (Avatar) {
|
|
179
|
+
return <Avatar />
|
|
180
|
+
}
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
3. **使用完整的 RegistryKey**
|
|
184
|
+
```typescript
|
|
185
|
+
// ✅ 推荐:完整路径
|
|
186
|
+
useClientComponent('userModule.userComponents.Avatar')
|
|
187
|
+
|
|
188
|
+
// ⚠️ 当前版本也需要完整路径(未来会支持短路径)
|
|
189
|
+
useClientComponent('userComponents.Avatar')
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
4. **提取类型定义**
|
|
193
|
+
```typescript
|
|
194
|
+
// 在单独的文件中定义类型
|
|
195
|
+
type UseAuthHook = () => { isAuthenticated: boolean; user: any }
|
|
196
|
+
|
|
197
|
+
// 在使用时引用
|
|
198
|
+
const useAuth = useClientHook<UseAuthHook>('...')
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### ❌ 避免的做法
|
|
202
|
+
|
|
203
|
+
1. **不要忽略空值检查**
|
|
204
|
+
```typescript
|
|
205
|
+
// ❌ 危险:可能运行时错误
|
|
206
|
+
const Avatar = useClientComponent('...')
|
|
207
|
+
return <Avatar /> // Avatar 可能是 undefined
|
|
208
|
+
|
|
209
|
+
// ✅ 安全
|
|
210
|
+
const Avatar = useClientComponent('...')
|
|
211
|
+
return Avatar ? <Avatar /> : null
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
2. **不要硬编码魔法字符串**
|
|
215
|
+
```typescript
|
|
216
|
+
// ❌ 不推荐
|
|
217
|
+
const Avatar = useClientComponent('userModule.userComponents.Avatar')
|
|
218
|
+
|
|
219
|
+
// ✅ 推荐:使用常量
|
|
220
|
+
const AVATAR_COMPONENT = 'userModule.userComponents.Avatar'
|
|
221
|
+
const Avatar = useClientComponent(AVATAR_COMPONENT)
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
3. **不要在循环中调用 Hook**
|
|
225
|
+
```typescript
|
|
226
|
+
// ❌ 违反 React Hooks 规则
|
|
227
|
+
componentNames.forEach(name => {
|
|
228
|
+
const Component = useClientComponent(name) // 错误!
|
|
229
|
+
})
|
|
230
|
+
|
|
231
|
+
// ✅ 正确:在顶层调用
|
|
232
|
+
const Component1 = useClientComponent('module.service.Component1')
|
|
233
|
+
const Component2 = useClientComponent('module.service.Component2')
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
## 常见问题
|
|
237
|
+
|
|
238
|
+
### Q: 为什么返回的是 `undefined`?
|
|
239
|
+
|
|
240
|
+
A: 可能的原因:
|
|
241
|
+
1. 资源未注册(检查模块是否正确加载)
|
|
242
|
+
2. RegistryKey 拼写错误
|
|
243
|
+
3. 模块尚未加载完成
|
|
244
|
+
|
|
245
|
+
解决方法:
|
|
246
|
+
- 检查控制台警告信息
|
|
247
|
+
- 确认模块已正确声明和加载
|
|
248
|
+
- 验证 RegistryKey 格式是否正确
|
|
249
|
+
|
|
250
|
+
### Q: 如何实现模块内引用(省略 moduleName)?
|
|
251
|
+
|
|
252
|
+
A: 当前版本需要显式传递完整路径。未来会通过 `ModuleContext` 自动获取当前模块名,届时可以这样使用:
|
|
253
|
+
|
|
254
|
+
```typescript
|
|
255
|
+
// 未来版本(TODO)
|
|
256
|
+
const Avatar = useClientComponent('userComponents.Avatar') // 自动补全为 'currentModule.userComponents.Avatar'
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
### Q: 如何调试资源查找问题?
|
|
260
|
+
|
|
261
|
+
A: Hook 会在找不到资源时输出警告信息:
|
|
262
|
+
|
|
263
|
+
```
|
|
264
|
+
[useClientComponent] Component not found: "userModule.userComponents.Avatar"
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
检查:
|
|
268
|
+
1. 模块是否正确加载
|
|
269
|
+
2. 服务是否正确注册
|
|
270
|
+
3. RegistryKey 是否匹配
|
|
271
|
+
|
|
272
|
+
## 完整示例
|
|
273
|
+
|
|
274
|
+
查看以下文件了解完整的使用示例:
|
|
275
|
+
- `src/hooks-example.tsx` - 详细的使用示例
|
|
276
|
+
- `../../packages/ssr/src/demo/client-modules.tsx` - SSR 演示项目中的实际应用
|
|
277
|
+
|
|
278
|
+
## 相关文档
|
|
279
|
+
|
|
280
|
+
- [前端模块接口设计](../../spec/前端模块接口设计.md)
|
|
281
|
+
- [前端插件式架构设计](../../spec/前端插件式架构设计.md)
|