@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
package/examples/hello-world/node_modules/@linyjs/client-module-interface/IMPLEMENTATION_SUMMARY.md
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
# 实现总结
|
|
2
|
+
|
|
3
|
+
## 已完成的工作
|
|
4
|
+
|
|
5
|
+
### 1. 核心 Hook 实现
|
|
6
|
+
|
|
7
|
+
在 `packages/client-module-interface/src/hooks.ts` 中实现了三个资源消费 Hook:
|
|
8
|
+
|
|
9
|
+
#### useClientComponent
|
|
10
|
+
- 从 `ClientComponentsContext` 获取 React 组件
|
|
11
|
+
- 支持跨模块引用(完整路径)和模块内引用(短路径)
|
|
12
|
+
- 提供类型安全的泛型参数 `<P = any>`
|
|
13
|
+
- 找不到组件时返回 `undefined` 并输出警告
|
|
14
|
+
|
|
15
|
+
#### useClientHook
|
|
16
|
+
- 从 `ClientHooksContext` 获取自定义 Hook
|
|
17
|
+
- 支持泛型类型约束 `<T extends Function>`
|
|
18
|
+
- 找不到 Hook 时返回 `undefined` 并输出警告
|
|
19
|
+
|
|
20
|
+
#### useClientService
|
|
21
|
+
- 从 `ClientServicesContext` 获取服务实例
|
|
22
|
+
- 支持泛型类型约束 `<T = any>`
|
|
23
|
+
- 找不到服务时返回 `undefined` 并输出警告
|
|
24
|
+
|
|
25
|
+
### 2. 路径解析机制
|
|
26
|
+
|
|
27
|
+
实现了 `resolveRegistryKey` 函数,支持两种引用格式:
|
|
28
|
+
|
|
29
|
+
- **跨模块引用**:`'moduleName.serviceTag.name'` → 直接使用
|
|
30
|
+
- **模块内引用**:`'serviceTag.name'` → 需要补全模块名(当前版本暂不支持自动补全)
|
|
31
|
+
|
|
32
|
+
### 3. 导出配置
|
|
33
|
+
|
|
34
|
+
在 `src/index.ts` 中导出了所有三个 Hook:
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
export {
|
|
38
|
+
useClientComponent,
|
|
39
|
+
useClientHook,
|
|
40
|
+
useClientService,
|
|
41
|
+
} from './hooks.js'
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### 4. 文档和示例
|
|
45
|
+
|
|
46
|
+
创建了以下文档文件:
|
|
47
|
+
|
|
48
|
+
- **README.md** - 包的整体说明和使用指南
|
|
49
|
+
- **HOOKS_USAGE.md** - Hooks 的详细使用指南和最佳实践
|
|
50
|
+
- **hooks-example.tsx** - 完整的使用示例代码
|
|
51
|
+
|
|
52
|
+
## 设计特点
|
|
53
|
+
|
|
54
|
+
### 1. 符合设计规范
|
|
55
|
+
|
|
56
|
+
严格按照 [前端模块接口设计.md](../../spec/前端模块接口设计.md) 第 159-200 行的要求实现:
|
|
57
|
+
|
|
58
|
+
- ✅ 支持模块内引用和跨模块引用
|
|
59
|
+
- ✅ 使用 React Context 消费资源
|
|
60
|
+
- ✅ 遵循 RegistryKey 命名规范
|
|
61
|
+
- ✅ 提供类型安全的泛型接口
|
|
62
|
+
|
|
63
|
+
### 2. 类型安全
|
|
64
|
+
|
|
65
|
+
所有 Hook 都支持泛型参数,确保类型安全:
|
|
66
|
+
|
|
67
|
+
```typescript
|
|
68
|
+
// 组件
|
|
69
|
+
const Avatar = useClientComponent<UserAvatarProps>('...')
|
|
70
|
+
|
|
71
|
+
// Hook
|
|
72
|
+
const useAuth = useClientHook<UseAuthHookType>('...')
|
|
73
|
+
|
|
74
|
+
// 服务
|
|
75
|
+
const userService = useClientService<IUserService>('...')
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### 3. 错误处理
|
|
79
|
+
|
|
80
|
+
- 资源未找到时返回 `undefined` 而非抛出异常
|
|
81
|
+
- 输出清晰的警告信息,便于调试
|
|
82
|
+
- 允许调用方进行优雅降级处理
|
|
83
|
+
|
|
84
|
+
### 4. 可扩展性
|
|
85
|
+
|
|
86
|
+
预留了 `useCurrentModuleName` Hook 的实现位置,未来可以通过 `ModuleContext` 自动获取当前模块名,实现真正的模块内短路径引用。
|
|
87
|
+
|
|
88
|
+
## 文件结构
|
|
89
|
+
|
|
90
|
+
```
|
|
91
|
+
packages/client-module-interface/
|
|
92
|
+
├── src/
|
|
93
|
+
│ ├── hooks.ts # 核心 Hook 实现
|
|
94
|
+
│ ├── hooks-example.tsx # 使用示例
|
|
95
|
+
│ ├── index.ts # 导出配置(已更新)
|
|
96
|
+
│ └── ...其他文件
|
|
97
|
+
├── dist/ # 编译输出
|
|
98
|
+
│ ├── hooks.js
|
|
99
|
+
│ ├── hooks.d.ts
|
|
100
|
+
│ └── ...其他文件
|
|
101
|
+
├── README.md # 包说明文档
|
|
102
|
+
└── HOOKS_USAGE.md # Hooks 使用指南
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## 使用方式
|
|
106
|
+
|
|
107
|
+
### 基本用法
|
|
108
|
+
|
|
109
|
+
```typescript
|
|
110
|
+
import {
|
|
111
|
+
useClientComponent,
|
|
112
|
+
useClientHook,
|
|
113
|
+
useClientService
|
|
114
|
+
} from '@ling/client-module-interface'
|
|
115
|
+
|
|
116
|
+
function MyComponent() {
|
|
117
|
+
// 获取组件
|
|
118
|
+
const Avatar = useClientComponent('userModule.userComponents.Avatar')
|
|
119
|
+
|
|
120
|
+
// 获取 Hook
|
|
121
|
+
type UseAuthHook = () => { isAuthenticated: boolean }
|
|
122
|
+
const useAuth = useClientHook<UseAuthHook>('authModule.authHooks.useAuth')
|
|
123
|
+
|
|
124
|
+
// 获取服务
|
|
125
|
+
const userService = useClientService<IUserService>('userModule.userService')
|
|
126
|
+
|
|
127
|
+
return (
|
|
128
|
+
<div>
|
|
129
|
+
{Avatar && <Avatar userId="123" />}
|
|
130
|
+
</div>
|
|
131
|
+
)
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## 与现有代码的集成
|
|
136
|
+
|
|
137
|
+
这些 Hook 可以与现有的 SSR 演示项目无缝集成。例如,在 `packages/ssr/src/demo/client-modules.tsx` 中,可以这样使用:
|
|
138
|
+
|
|
139
|
+
```typescript
|
|
140
|
+
// 之前:直接使用 useContext
|
|
141
|
+
const components = useContext(ClientComponentsContext)
|
|
142
|
+
const Avatar = components['userModule.userComponents.Avatar']
|
|
143
|
+
|
|
144
|
+
// 现在:使用 Hook(更简洁)
|
|
145
|
+
const Avatar = useClientComponent('userModule.userComponents.Avatar')
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## 后续改进建议
|
|
149
|
+
|
|
150
|
+
1. **实现 ModuleContext**:添加 `ModuleContext` 来跟踪当前模块,实现真正的模块内短路径引用
|
|
151
|
+
2. **添加缓存机制**:对查找结果进行缓存,提升性能
|
|
152
|
+
3. **支持懒加载**:支持按需加载模块和资源
|
|
153
|
+
4. **添加 DevTools 支持**:提供开发者工具,方便调试资源注册和消费
|
|
154
|
+
|
|
155
|
+
## 测试建议
|
|
156
|
+
|
|
157
|
+
虽然本次实现未包含单元测试,但建议后续添加:
|
|
158
|
+
|
|
159
|
+
1. Hook 返回值测试
|
|
160
|
+
2. 路径解析逻辑测试
|
|
161
|
+
3. 空值处理测试
|
|
162
|
+
4. 类型安全检查测试
|
|
163
|
+
|
|
164
|
+
## 总结
|
|
165
|
+
|
|
166
|
+
本次实现完成了 `client-module-interface` 包中的三个核心 Hook,使开发者能够方便地在模块中消费注册的资源。实现严格遵循设计文档,提供了类型安全、错误处理和良好的开发体验。
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# 快速参考
|
|
2
|
+
|
|
3
|
+
## 导入
|
|
4
|
+
|
|
5
|
+
```typescript
|
|
6
|
+
import {
|
|
7
|
+
useClientComponent,
|
|
8
|
+
useClientHook,
|
|
9
|
+
useClientService
|
|
10
|
+
} from '@ling/client-module-interface'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## API 速查
|
|
14
|
+
|
|
15
|
+
### useClientComponent
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
const Component = useClientComponent<PropsType>('moduleName.serviceTag.componentName')
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
**参数**:`refPath: string` - 组件的 RegistryKey
|
|
22
|
+
**返回**:`IComponent<PropsType> | undefined`
|
|
23
|
+
|
|
24
|
+
**示例**:
|
|
25
|
+
```typescript
|
|
26
|
+
const Avatar = useClientComponent('userModule.userComponents.Avatar')
|
|
27
|
+
// 使用
|
|
28
|
+
{Avatar && <Avatar userId="123" />}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
### useClientHook
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
const hook = useClientHook<HookType>('moduleName.serviceTag.hookName')
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
**参数**:`refPath: string` - Hook 的 RegistryKey
|
|
40
|
+
**返回**:`HookType | undefined`
|
|
41
|
+
|
|
42
|
+
**示例**:
|
|
43
|
+
```typescript
|
|
44
|
+
type UseAuthHook = () => { isAuthenticated: boolean }
|
|
45
|
+
const useAuth = useClientHook<UseAuthHook>('authModule.authHooks.useAuth')
|
|
46
|
+
// 使用
|
|
47
|
+
const authState = useAuth ? useAuth() : null
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
### useClientService
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
const service = useClientService<ServiceType>('moduleName.serviceTag')
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
**参数**:`refPath: string` - 服务的 RegistryKey
|
|
59
|
+
**返回**:`ServiceType | undefined`
|
|
60
|
+
|
|
61
|
+
**示例**:
|
|
62
|
+
```typescript
|
|
63
|
+
interface IUserService {
|
|
64
|
+
getUser(id: string): Promise<User>
|
|
65
|
+
}
|
|
66
|
+
const userService = useClientService<IUserService>('userModule.userService')
|
|
67
|
+
// 使用
|
|
68
|
+
if (userService) {
|
|
69
|
+
const user = await userService.getUser('123')
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
## RegistryKey 格式
|
|
76
|
+
|
|
77
|
+
| 资源类型 | 格式 | 示例 |
|
|
78
|
+
|---------|------|------|
|
|
79
|
+
| 组件 | `moduleName.serviceTag.componentName` | `'userModule.userComponents.Avatar'` |
|
|
80
|
+
| Hook | `moduleName.serviceTag.hookName` | `'authModule.authHooks.useAuth'` |
|
|
81
|
+
| 服务 | `moduleName.serviceTag` | `'userModule.userService'` |
|
|
82
|
+
| 全局状态 | `moduleName.serviceTag.atomName` | `'userModule.userState.user'` |
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## 注意事项
|
|
87
|
+
|
|
88
|
+
✅ **必须做**:
|
|
89
|
+
- 进行空值检查(返回值可能是 `undefined`)
|
|
90
|
+
- 使用泛型提供类型约束
|
|
91
|
+
- 使用完整的 RegistryKey(包含 moduleName)
|
|
92
|
+
|
|
93
|
+
❌ **不要做**:
|
|
94
|
+
- 忽略空值检查
|
|
95
|
+
- 在循环中调用 Hook
|
|
96
|
+
- 硬编码魔法字符串
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
## 常见模式
|
|
101
|
+
|
|
102
|
+
### 条件渲染
|
|
103
|
+
```typescript
|
|
104
|
+
const Avatar = useClientComponent('...')
|
|
105
|
+
return Avatar ? <Avatar /> : <Fallback />
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### 错误处理
|
|
109
|
+
```typescript
|
|
110
|
+
const service = useClientService<IMyService>('...')
|
|
111
|
+
if (!service) {
|
|
112
|
+
console.error('Service not found')
|
|
113
|
+
return null
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### 混合使用
|
|
118
|
+
```typescript
|
|
119
|
+
const Component = useClientComponent('...')
|
|
120
|
+
const hook = useClientHook<HookType>('...')
|
|
121
|
+
const service = useClientService<ServiceType>('...')
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## 更多信息
|
|
127
|
+
|
|
128
|
+
- 📖 [完整使用指南](./HOOKS_USAGE.md)
|
|
129
|
+
- 📝 [使用示例](./src/hooks-example.tsx)
|
|
130
|
+
- 📋 [包说明](./README.md)
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
# @ling/client-module-interface
|
|
2
|
+
|
|
3
|
+
前端模块接口定义包,提供插件式架构所需的类型定义和工具函数。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @ling/client-module-interface
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 核心功能
|
|
12
|
+
|
|
13
|
+
### 1. 依赖注入类型
|
|
14
|
+
|
|
15
|
+
- `IModule` - 模块定义
|
|
16
|
+
- `IServiceDef` - 服务定义
|
|
17
|
+
- `IModuleHandler` - 模块生命周期处理器
|
|
18
|
+
- `IModuleContainer` - 模块容器
|
|
19
|
+
|
|
20
|
+
### 2. 前端领域类型
|
|
21
|
+
|
|
22
|
+
- `IComponent` - React 组件类型
|
|
23
|
+
- `IRoute` - 路由定义
|
|
24
|
+
- `IRouteGuard` - 路由守卫
|
|
25
|
+
- `IRouteLoader` - 路由数据加载器
|
|
26
|
+
|
|
27
|
+
### 3. 服务接口
|
|
28
|
+
|
|
29
|
+
- `IRouteService` - 路由服务
|
|
30
|
+
- `IGlobalStateService` - 全局状态服务(jotai atoms)
|
|
31
|
+
- `IComponentListService` - 组件列表服务
|
|
32
|
+
- `IHooksService` - Hooks 服务
|
|
33
|
+
|
|
34
|
+
### 4. 资源消费 Hooks ⭐
|
|
35
|
+
|
|
36
|
+
#### useClientComponent
|
|
37
|
+
|
|
38
|
+
从全局注册表中获取 React 组件。
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
import { useClientComponent } from '@ling/client-module-interface'
|
|
42
|
+
|
|
43
|
+
// 跨模块引用
|
|
44
|
+
const Avatar = useClientComponent('userModule.userComponents.Avatar')
|
|
45
|
+
|
|
46
|
+
// 在组件中使用
|
|
47
|
+
function UserProfile() {
|
|
48
|
+
return (
|
|
49
|
+
<div>
|
|
50
|
+
{Avatar && <Avatar userId="123" size="large" />}
|
|
51
|
+
</div>
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
#### useClientHook
|
|
57
|
+
|
|
58
|
+
从全局注册表中获取自定义 Hook。
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
import { useClientHook } from '@ling/client-module-interface'
|
|
62
|
+
|
|
63
|
+
// 跨模块引用
|
|
64
|
+
type UseAuthHook = () => { isAuthenticated: boolean; user: any }
|
|
65
|
+
const useAuth = useClientHook<UseAuthHook>('authModule.authHooks.useAuth')
|
|
66
|
+
|
|
67
|
+
// 在组件中使用
|
|
68
|
+
function AuthStatus() {
|
|
69
|
+
const authState = useAuth ? useAuth() : null
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<div>
|
|
73
|
+
{authState?.isAuthenticated ? '已登录' : '未登录'}
|
|
74
|
+
</div>
|
|
75
|
+
)
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
#### useClientService
|
|
80
|
+
|
|
81
|
+
从全局注册表中获取服务实例。
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
import { useClientService } from '@ling/client-module-interface'
|
|
85
|
+
|
|
86
|
+
interface IUserService {
|
|
87
|
+
getUser(id: string): Promise<User>
|
|
88
|
+
updateUser(id: string, data: Partial<User>): Promise<void>
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// 跨模块引用
|
|
92
|
+
const userService = useClientService<IUserService>('userModule.userService')
|
|
93
|
+
|
|
94
|
+
// 在组件中使用
|
|
95
|
+
function UserManagement() {
|
|
96
|
+
const handleLoadUser = async () => {
|
|
97
|
+
if (userService) {
|
|
98
|
+
const user = await userService.getUser('123')
|
|
99
|
+
console.log(user)
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return <button onClick={handleLoadUser}>加载用户</button>
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### 5. React Context
|
|
108
|
+
|
|
109
|
+
- `ClientComponentsContext` - 组件注册表 Context
|
|
110
|
+
- `ClientGlobalStateContext` - 全局状态 Context(jotai atoms)
|
|
111
|
+
- `ClientServicesContext` - 服务注册表 Context
|
|
112
|
+
- `ClientHooksContext` - Hooks 注册表 Context
|
|
113
|
+
|
|
114
|
+
## 引用规则
|
|
115
|
+
|
|
116
|
+
### 模块内引用 vs 跨模块引用
|
|
117
|
+
|
|
118
|
+
| 资源类型 | 模块内引用 | 跨模块引用 |
|
|
119
|
+
|---------|-----------|-----------|
|
|
120
|
+
| 组件 | `serviceTag.componentName` | `moduleName.serviceTag.componentName` |
|
|
121
|
+
| Hook | `serviceTag.hookName` | `moduleName.serviceTag.hookName` |
|
|
122
|
+
| 服务 | `serviceTag` | `moduleName.serviceTag` |
|
|
123
|
+
| 全局状态 | `serviceTag.atomName` | `moduleName.serviceTag.atomName` |
|
|
124
|
+
|
|
125
|
+
**注意**:当前版本中,模块内引用需要显式传递完整路径(包含 moduleName),未来会通过 ModuleContext 自动获取当前模块名。
|
|
126
|
+
|
|
127
|
+
### RegistryKey 格式
|
|
128
|
+
|
|
129
|
+
- 组件:`moduleName.serviceTag.componentName`
|
|
130
|
+
- 示例:`'userModule.userComponents.Avatar'`
|
|
131
|
+
- Hook:`moduleName.serviceTag.hookName`
|
|
132
|
+
- 示例:`'authModule.authHooks.useAuth'`
|
|
133
|
+
- 服务:`moduleName.serviceTag`
|
|
134
|
+
- 示例:`'userModule.userService'`
|
|
135
|
+
- 全局状态:`moduleName.serviceTag.atomName`
|
|
136
|
+
- 示例:`'userModule.userState.user'`
|
|
137
|
+
|
|
138
|
+
## 最佳实践
|
|
139
|
+
|
|
140
|
+
### 1. 类型安全
|
|
141
|
+
|
|
142
|
+
使用泛型参数为服务和 Hook 提供类型约束:
|
|
143
|
+
|
|
144
|
+
```typescript
|
|
145
|
+
// ✅ 推荐
|
|
146
|
+
const userService = useClientService<IUserService>('userModule.userService')
|
|
147
|
+
const useAuth = useClientHook<UseAuthHook>('authModule.authHooks.useAuth')
|
|
148
|
+
|
|
149
|
+
// ❌ 不推荐(失去类型检查)
|
|
150
|
+
const userService = useClientService('userModule.userService')
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### 2. 空值检查
|
|
154
|
+
|
|
155
|
+
所有 Hook 都可能返回 `undefined`(资源未找到时),使用前应该进行空值检查:
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
const Avatar = useClientComponent('userModule.userComponents.Avatar')
|
|
159
|
+
|
|
160
|
+
// ✅ 推荐:空值检查
|
|
161
|
+
if (Avatar) {
|
|
162
|
+
return <Avatar userId="123" />
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// ✅ 推荐:可选链
|
|
166
|
+
return Avatar ? <Avatar userId="123" /> : null
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### 3. 命名规范
|
|
170
|
+
|
|
171
|
+
- **组件**:PascalCase,如 `Avatar`、`UserProfile`
|
|
172
|
+
- **Hook**:camelCase 且以 `use` 开头,如 `useAuth`、`useUser`
|
|
173
|
+
- **服务**:camelCase,如 `userService`、`apiService`
|
|
174
|
+
|
|
175
|
+
### 4. 模块设计
|
|
176
|
+
|
|
177
|
+
每个模块应该明确声明提供的服务类型:
|
|
178
|
+
|
|
179
|
+
```typescript
|
|
180
|
+
// 组件服务
|
|
181
|
+
class UserComponentService implements IComponentListService {
|
|
182
|
+
components = {
|
|
183
|
+
Avatar: UserAvatar,
|
|
184
|
+
Profile: UserProfile,
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// Hook 服务
|
|
189
|
+
class AuthHooksService implements IHooksService {
|
|
190
|
+
hooks = {
|
|
191
|
+
useAuth,
|
|
192
|
+
usePermissions,
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// 普通服务
|
|
197
|
+
class UserServiceImpl implements IUserService {
|
|
198
|
+
// ...
|
|
199
|
+
}
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
## 示例项目
|
|
203
|
+
|
|
204
|
+
查看 `src/hooks-example.tsx` 文件了解完整的使用示例。
|
|
205
|
+
|
|
206
|
+
## 相关文档
|
|
207
|
+
|
|
208
|
+
- [前端模块接口设计](../../spec/前端模块接口设计.md)
|
|
209
|
+
- [前端插件式架构设计](../../spec/前端插件式架构设计.md)
|
|
210
|
+
- [依赖注入机制设计](../../spec/依赖注入机制设计.md)
|
|
211
|
+
|
|
212
|
+
## License
|
|
213
|
+
|
|
214
|
+
MIT
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@linyjs/client-module-interface",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "tsc -b",
|
|
16
|
+
"clean": "rm -rf dist *.tsbuildinfo"
|
|
17
|
+
},
|
|
18
|
+
"peerDependencies": {
|
|
19
|
+
"react": "^19.0.0"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@types/react": "^19.1.6",
|
|
23
|
+
"react": "^19.1.0",
|
|
24
|
+
"typescript": "^5.7.0"
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 客户端应用接口
|
|
3
|
+
* 详见 [前端插件式架构设计](../../spec/前端插件式架构设计.md)
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { IModule, IModuleHandler } from './di.js'
|
|
7
|
+
import type { IRoute, IComponent } from './domain.js'
|
|
8
|
+
import type { IRouterAdapter } from './router.js'
|
|
9
|
+
import type { IAtom } from './interfaces.js'
|
|
10
|
+
|
|
11
|
+
/** 客户端注册表 */
|
|
12
|
+
export interface IClientRegistries {
|
|
13
|
+
/** 路由注册表(按 basePath 前缀分组) */
|
|
14
|
+
routes: IRoute[]
|
|
15
|
+
/** 组件注册表 */
|
|
16
|
+
components: Record<string, IComponent>
|
|
17
|
+
/** 全局状态注册表(jotai atoms) */
|
|
18
|
+
atoms: Record<string, IAtom>
|
|
19
|
+
/** 服务注册表 */
|
|
20
|
+
services: Record<string, any>
|
|
21
|
+
/** Hook 注册表 */
|
|
22
|
+
hooks: Record<string, Function>
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** 客户端应用接口 */
|
|
26
|
+
export interface IClientApplication {
|
|
27
|
+
/** 设置模块生命周期处理器 */
|
|
28
|
+
setHandler(handler: IModuleHandler): void
|
|
29
|
+
|
|
30
|
+
/** 设置路由适配器 */
|
|
31
|
+
setRouterAdapter(adapter: IRouterAdapter): void
|
|
32
|
+
|
|
33
|
+
/** 加载一组模块,按依赖拓扑排序后由容器实例化服务 */
|
|
34
|
+
loadModules(modules: IModule[]): Promise<void>
|
|
35
|
+
|
|
36
|
+
/** 获取所有注册表 */
|
|
37
|
+
getRegistries(): IClientRegistries
|
|
38
|
+
|
|
39
|
+
/** 获取 React 根组件(CSR 模式,包含路由 + Context) */
|
|
40
|
+
getReactRootElement(): import('react').JSX.Element
|
|
41
|
+
|
|
42
|
+
/** SSR 模式:hydrate 已渲染的 HTML */
|
|
43
|
+
hydrate(ssrState: { loaderData?: any }): Promise<void>
|
|
44
|
+
|
|
45
|
+
/** CSR 模式:挂载根组件到 DOM */
|
|
46
|
+
run(): Promise<void>
|
|
47
|
+
|
|
48
|
+
/** 卸载所有已加载模块 */
|
|
49
|
+
destroyAll(): Promise<void>
|
|
50
|
+
}
|