@modern-js/main-doc 2.0.0-beta.2 → 2.0.0-beta.3
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/.turbo/turbo-build.log +1 -1
- package/en/docusaurus-plugin-content-docs/current/apis/app/commands/new.md +0 -2
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/core/bootstrap.md +17 -3
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/model/create-app.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/model/use-store.md +0 -22
- package/en/docusaurus-plugin-content-docs/current/components/reduck-migration.md +1 -0
- package/en/docusaurus-plugin-content-docs/current/configure/app/dev/asset-prefix.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/dev/hmr.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/dev/https.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/dev/port.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/dev/progress-bar.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/dev/start-url.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/experiments/lazy-compilation.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/html/app-icon.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/html/crossorigin.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/html/disable-html-folder.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/html/favicon-by-entries.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/html/favicon.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/html/inject-by-entries.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/html/inject.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/html/meta-by-entries.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/html/meta.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/html/mount-id.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/html/template-by-entries.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/html/template-parameters-by-entries.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/html/template-parameters.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/html/template.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/html/title-by-entries.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/html/title.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/output/asset-prefix.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/output/assets-retry.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/output/charset.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/output/clean-dist-path.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/output/convert-to-rem.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/output/copy.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/output/css-module-local-ident-name.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/output/data-uri-limit.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/output/disable-css-extract.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/output/disable-css-module-extension.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/output/disable-filename-hash.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/output/disable-inline-runtime-chunk.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/output/disable-minimize.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/output/disable-source-map.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/output/disable-ts-checker.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/output/dist-path.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/output/enable-asset-fallback.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/output/enable-asset-manifest.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/output/enable-css-module-tsdeclaration.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/output/enable-inline-scripts.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/output/enable-inline-styles.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/output/enable-latest-decorators.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/output/externals.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/output/filename.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/output/legal-comments.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/output/override-browserslist.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/output/polyfill.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/output/svg-default-export.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/performance/build-cache.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/performance/bundle-analyze.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/performance/chunk-split.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/performance/print-file-size.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/performance/profile.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/performance/remove-console.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/performance/remove-moment-locale.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/plugins.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/security/sri.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/source/alias.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/source/compile-js-data-uri.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/source/define.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/source/exclude.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/source/global-vars.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/source/include.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/source/module-scopes.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/source/pre-entry.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/source/resolve-extension-prefix.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/source/resolve-main-fields.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/tools/autoprefixer.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/tools/babel.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/tools/css-extract.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/tools/css-loader.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/tools/dev-server.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/tools/html-plugin.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/tools/inspector.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/tools/less.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/tools/minify-css.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/tools/postcss.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/tools/pug.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/tools/sass.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/tools/style-loader.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/tools/styled-components.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/tools/swc.md +42 -0
- package/en/docusaurus-plugin-content-docs/current/configure/app/tools/terser.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/tools/ts-checker.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/tools/ts-loader.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/tools/webpack-chain.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/tools/webpack.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/guides/basic-features/builder.md +46 -0
- package/en/docusaurus-plugin-content-docs/current.json +18 -18
- package/package.json +3 -3
- package/scripts/config.ts +2 -2
- package/zh/apis/app/commands/new.md +0 -2
- package/zh/apis/app/runtime/app/_category_.json +1 -1
- package/zh/apis/app/runtime/bff/_category_.json +1 -1
- package/zh/apis/app/runtime/core/_category_.json +1 -1
- package/zh/apis/app/runtime/core/bootstrap.md +17 -3
- package/zh/apis/app/runtime/model/_category_.json +1 -1
- package/zh/apis/app/runtime/model/create-app.md +1 -1
- package/zh/apis/app/runtime/model/use-store.md +1 -23
- package/zh/apis/app/runtime/router/_category_.json +1 -1
- package/zh/apis/app/runtime/ssr/_category_.json +1 -1
- package/zh/apis/app/runtime/testing/_category_.json +1 -1
- package/zh/apis/app/runtime/utility/_category_.json +1 -1
- package/zh/apis/app/runtime/web-server/_category_.json +1 -1
- package/zh/components/reduck-migration.md +1 -0
- package/zh/configure/app/dev/asset-prefix.md +1 -1
- package/zh/configure/app/dev/hmr.md +1 -1
- package/zh/configure/app/dev/https.md +1 -1
- package/zh/configure/app/dev/port.md +1 -1
- package/zh/configure/app/dev/progress-bar.md +1 -1
- package/zh/configure/app/dev/start-url.md +1 -1
- package/zh/configure/app/experiments/_category_.json +4 -0
- package/zh/configure/app/experiments/lazy-compilation.md +1 -1
- package/zh/configure/app/html/_category_.json +4 -0
- package/zh/configure/app/html/app-icon.md +1 -1
- package/zh/configure/app/html/crossorigin.md +1 -1
- package/zh/configure/app/html/disable-html-folder.md +1 -1
- package/zh/configure/app/html/favicon-by-entries.md +1 -1
- package/zh/configure/app/html/favicon.md +1 -1
- package/zh/configure/app/html/inject-by-entries.md +1 -1
- package/zh/configure/app/html/inject.md +1 -1
- package/zh/configure/app/html/meta-by-entries.md +1 -1
- package/zh/configure/app/html/meta.md +1 -1
- package/zh/configure/app/html/mount-id.md +1 -1
- package/zh/configure/app/html/template-by-entries.md +1 -1
- package/zh/configure/app/html/template-parameters-by-entries.md +1 -1
- package/zh/configure/app/html/template-parameters.md +1 -1
- package/zh/configure/app/html/template.md +1 -1
- package/zh/configure/app/html/title-by-entries.md +1 -1
- package/zh/configure/app/html/title.md +1 -1
- package/zh/configure/app/output/asset-prefix.md +1 -1
- package/zh/configure/app/output/assets-retry.md +1 -1
- package/zh/configure/app/output/charset.md +1 -1
- package/zh/configure/app/output/clean-dist-path.md +1 -1
- package/zh/configure/app/output/convert-to-rem.md +1 -1
- package/zh/configure/app/output/copy.md +1 -1
- package/zh/configure/app/output/css-module-local-ident-name.md +1 -1
- package/zh/configure/app/output/data-uri-limit.md +1 -1
- package/zh/configure/app/output/disable-css-extract.md +1 -1
- package/zh/configure/app/output/disable-css-module-extension.md +1 -1
- package/zh/configure/app/output/disable-filename-hash.md +1 -1
- package/zh/configure/app/output/disable-inline-runtime-chunk.md +1 -1
- package/zh/configure/app/output/disable-minimize.md +1 -1
- package/zh/configure/app/output/disable-source-map.md +1 -1
- package/zh/configure/app/output/disable-ts-checker.md +1 -1
- package/zh/configure/app/output/dist-path.md +1 -1
- package/zh/configure/app/output/enable-asset-fallback.md +1 -1
- package/zh/configure/app/output/enable-asset-manifest.md +1 -1
- package/zh/configure/app/output/enable-css-module-tsdeclaration.md +1 -1
- package/zh/configure/app/output/enable-inline-scripts.md +1 -1
- package/zh/configure/app/output/enable-inline-styles.md +1 -1
- package/zh/configure/app/output/enable-latest-decorators.md +1 -1
- package/zh/configure/app/output/externals.md +1 -1
- package/zh/configure/app/output/filename.md +1 -1
- package/zh/configure/app/output/legal-comments.md +1 -1
- package/zh/configure/app/output/override-browserslist.md +1 -1
- package/zh/configure/app/output/polyfill.md +1 -1
- package/zh/configure/app/output/ssg.md +118 -114
- package/zh/configure/app/output/svg-default-export.md +1 -1
- package/zh/configure/app/performance/_category_.json +4 -0
- package/zh/configure/app/performance/build-cache.md +1 -1
- package/zh/configure/app/performance/bundle-analyze.md +1 -1
- package/zh/configure/app/performance/chunk-split.md +1 -1
- package/zh/configure/app/performance/print-file-size.md +1 -1
- package/zh/configure/app/performance/profile.md +1 -1
- package/zh/configure/app/performance/remove-console.md +1 -1
- package/zh/configure/app/performance/remove-moment-locale.md +1 -1
- package/zh/configure/app/plugins.md +1 -1
- package/zh/configure/app/runtime/state.md +13 -0
- package/zh/configure/app/security/_category_.json +4 -0
- package/zh/configure/app/security/sri.md +1 -1
- package/zh/configure/app/server/ssr.md +0 -2
- package/zh/configure/app/source/alias.md +1 -1
- package/zh/configure/app/source/compile-js-data-uri.md +1 -1
- package/zh/configure/app/source/define.md +1 -1
- package/zh/configure/app/source/exclude.md +1 -1
- package/zh/configure/app/source/global-vars.md +1 -1
- package/zh/configure/app/source/include.md +1 -1
- package/zh/configure/app/source/module-scopes.md +1 -1
- package/zh/configure/app/source/pre-entry.md +1 -1
- package/zh/configure/app/source/resolve-extension-prefix.md +1 -1
- package/zh/configure/app/source/resolve-main-fields.md +1 -1
- package/zh/configure/app/tools/autoprefixer.md +1 -1
- package/zh/configure/app/tools/babel.md +1 -1
- package/zh/configure/app/tools/css-extract.md +1 -1
- package/zh/configure/app/tools/css-loader.md +1 -1
- package/zh/configure/app/tools/dev-server.md +1 -1
- package/zh/configure/app/tools/html-plugin.md +1 -1
- package/zh/configure/app/tools/inspector.md +1 -1
- package/zh/configure/app/tools/less.md +1 -1
- package/zh/configure/app/tools/minify-css.md +1 -1
- package/zh/configure/app/tools/postcss.md +1 -1
- package/zh/configure/app/tools/pug.md +1 -1
- package/zh/configure/app/tools/sass.md +1 -1
- package/zh/configure/app/tools/style-loader.md +1 -1
- package/zh/configure/app/tools/styled-components.md +1 -1
- package/zh/configure/app/tools/swc.md +42 -0
- package/zh/configure/app/tools/terser.md +1 -1
- package/zh/configure/app/tools/ts-checker.md +1 -1
- package/zh/configure/app/tools/ts-loader.md +1 -1
- package/zh/configure/app/tools/webpack-chain.md +1 -1
- package/zh/configure/app/tools/webpack.md +1 -1
- package/zh/guides/advanced-features/custom-app.md +8 -2
- package/zh/guides/advanced-features/ssg.md +74 -63
- package/zh/guides/advanced-features/ssr.md +74 -11
- package/zh/guides/basic-features/builder.md +46 -0
- package/zh/guides/basic-features/css/_category_.json +1 -1
- package/zh/guides/basic-features/css/less-sass.md +1 -14
- package/zh/guides/basic-features/data-fetch.md +1 -1
- package/zh/guides/basic-features/env-vars.md +34 -0
- package/zh/guides/basic-features/routes.md +32 -35
- package/zh/guides/concept/entries.md +4 -4
- package/zh/guides/topic-detail/framework-plugin/extend.md +3 -4
- package/zh/{apis/app/runtime/plugin/hook-api.md → guides/topic-detail/framework-plugin/hook-list.md} +42 -135
- package/zh/{apis/app/runtime/plugin → guides/topic-detail/framework-plugin}/hook.md +2 -3
- package/zh/guides/topic-detail/framework-plugin/implement.md +21 -10
- package/zh/guides/topic-detail/framework-plugin/introduction.md +49 -0
- package/{en/docusaurus-plugin-content-docs/current/apis/app/runtime/plugin → zh/guides/topic-detail/framework-plugin}/plugin-api.md +3 -4
- package/zh/guides/topic-detail/framework-plugin/relationship.md +2 -3
- package/zh/guides/topic-detail/model/quick-start.md +4 -0
- package/zh/tutorials/first-app/c01-getting-started/1.2-minimal-mwa.md +2 -2
- package/zh/tutorials/first-app/c01-getting-started/1.4-enable-ssr.md +5 -2
- package/zh/tutorials/first-app/c02-generator-and-studio/2.2-boilerplates.md +4 -6
- package/zh/tutorials/first-app/c02-generator-and-studio/2.3-configuration.md +2 -4
- package/zh/tutorials/first-app/c03-ide/3.1-setting-up.md +1 -1
- package/zh/tutorials/first-app/c03-ide/3.2-hints-in-ide.md +44 -50
- package/zh/tutorials/first-app/c03-ide/3.3-autofix-in-ide.md +1 -1
- package/zh/tutorials/first-app/c03-ide/3.4-autofix-in-cli.md +4 -4
- package/zh/tutorials/first-app/c04-es6-plus-and-ts/4.1-use-es6-plus.md +8 -21
- package/zh/tutorials/first-app/c04-es6-plus-and-ts/4.2-use-typescript.md +37 -13
- package/zh/tutorials/first-app/c05-component/5.1-use-ui-library.md +3 -13
- package/zh/tutorials/first-app/c05-component/5.2-use-standalone-component.md +1 -21
- package/zh/tutorials/first-app/c06-css-and-component/6.1-css-in-js.md +9 -9
- package/zh/tutorials/first-app/c06-css-and-component/6.2-utility-class.md +9 -14
- package/zh/tutorials/first-app/c06-css-and-component/6.3-postcss.md +7 -7
- package/zh/tutorials/first-app/c06-css-and-component/6.4-design-system.md +1 -1
- package/zh/tutorials/first-app/c06-css-and-component/6.5-storybook.md +2 -2
- package/zh/tutorials/first-app/c06-css-and-component/6.6-testing.md +8 -17
- package/zh/tutorials/first-app/c07-app-entry/7.1-intro.md +23 -18
- package/zh/tutorials/first-app/c07-app-entry/7.2-add-entry-in-cli.md +30 -30
- package/zh/tutorials/first-app/c07-app-entry/7.3-manage-entries-by-hand.md +4 -9
- package/zh/tutorials/first-app/c08-client-side-routing/8.1-code-based-routing.md +66 -63
- package/zh/tutorials/first-app/c09-bff/9.2-enable-bff.md +35 -33
- package/zh/tutorials/first-app/c09-bff/9.3-fetch-bff.md +28 -102
- package/zh/tutorials/first-app/c10-model/10.1-application-architecture.md +4 -6
- package/zh/tutorials/first-app/c10-model/10.2-add-model.md +3 -3
- package/zh/tutorials/first-app/c10-model/10.3-use-model.md +21 -20
- package/zh/tutorials/first-app/c10-model/10.4-testing.md +2 -2
- package/zh/tutorials/first-app/c11-container/11.1-use-model-with-app-state.md +34 -68
- package/zh/tutorials/first-app/c11-container/11.2-add-container.md +40 -37
- package/zh/tutorials/first-app/c11-container/11.3-use-loader.md +6 -4
- package/zh/tutorials/first-app/c11-container/11.4-testing.md +2 -2
- package/zh/tutorials/foundations/introduction.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/default-alias.md +0 -25
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/plugin/_category_.json +0 -4
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/plugin/abstract.md +0 -26
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/plugin/hook-api.md +0 -896
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/plugin/hook.md +0 -170
- package/zh/apis/app/runtime/default-alias.md +0 -23
- package/zh/apis/app/runtime/plugin/_category_.json +0 -4
- package/zh/apis/app/runtime/plugin/abstract.md +0 -26
- package/zh/apis/app/runtime/plugin/plugin-api.md +0 -117
- package/zh/guides/basic-features/image.md +0 -43
- package/zh/guides/topic-detail/compile-speed.md +0 -182
- package/zh/guides/topic-detail/framework-plugin/abstract.md +0 -27
- package/zh/guides/troubleshooting/compile.md +0 -379
- package/zh/tutorials/first-app/c08-client-side-routing/8.2-file-based-routing.md +0 -310
|
@@ -2,18 +2,17 @@
|
|
|
2
2
|
title: 使用 Model
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
-
上一小节中,我们实现了 Model,已经把
|
|
5
|
+
上一小节中,我们实现了 Model,已经把 `page.tsx` `Index` 组件中原有的 UI 无关业务逻辑解耦出来。
|
|
6
6
|
|
|
7
|
-
这一小节中,我们使用这个 Model 直接把
|
|
7
|
+
这一小节中,我们使用这个 Model 直接把 `page.tsx` `Index` 组件重新还原出来,实现变得更简洁清晰:
|
|
8
8
|
|
|
9
|
-
```js title="src/contacts/
|
|
9
|
+
```js title="src/contacts/routes/page.tsx"
|
|
10
10
|
import { useEffect } from 'react';
|
|
11
11
|
import { useLocalModel } from '@modern-js/runtime/model';
|
|
12
|
-
import
|
|
13
|
-
import Item from '
|
|
14
|
-
import contacts from '../../models/contacts';
|
|
12
|
+
import contacts from './models/contacts';
|
|
13
|
+
import Item from './components/Item';
|
|
15
14
|
|
|
16
|
-
|
|
15
|
+
function Index() {
|
|
17
16
|
const [{ items, error, pending }, actions] = useLocalModel(contacts);
|
|
18
17
|
|
|
19
18
|
useEffect(() => {
|
|
@@ -22,23 +21,25 @@ const AllContacts = () => {
|
|
|
22
21
|
}
|
|
23
22
|
});
|
|
24
23
|
return (
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
24
|
+
<div className="container lg mx-auto">
|
|
25
|
+
{(items.length && (
|
|
26
|
+
<List
|
|
27
|
+
dataSource={items}
|
|
28
|
+
renderItem={info => <Item key={info.name} info={info} />}
|
|
29
|
+
/>
|
|
30
|
+
)) || (
|
|
31
|
+
<div className="p-4 items-center border-gray-200 border-b border-t custom-text-gray">
|
|
32
|
+
Pending...
|
|
33
|
+
</div>
|
|
34
|
+
)}
|
|
35
|
+
</div>
|
|
35
36
|
);
|
|
36
|
-
}
|
|
37
|
+
}
|
|
37
38
|
|
|
38
|
-
export default
|
|
39
|
+
export default Index;
|
|
39
40
|
```
|
|
40
41
|
|
|
41
|
-
以上代码跟上一章节中 `
|
|
42
|
+
以上代码跟上一章节中 `Index` 组件的代码等价。
|
|
42
43
|
|
|
43
44
|
`useLocalModel` 是 Modern.js 提供的 hooks API,可以使用 Model,在组件中提供 Model 中定义的 state,或通过 actions 调用 Model 中定义的 side effect 与 action,从而改变 Model 的 state。
|
|
44
45
|
|
|
@@ -17,14 +17,14 @@ import TabItem from '@theme/TabItem';
|
|
|
17
17
|
<TabItem value="macOS" label="macOS" default>
|
|
18
18
|
|
|
19
19
|
```bash
|
|
20
|
-
touch src/contacts/models/contacts.test.ts
|
|
20
|
+
touch src/contacts/routes/models/contacts.test.ts
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
</TabItem>
|
|
24
24
|
<TabItem value="Windows" label="Windows">
|
|
25
25
|
|
|
26
26
|
```powershell
|
|
27
|
-
ni src/contacts/models/contacts.test.ts
|
|
27
|
+
ni src/contacts/routes/models/contacts.test.ts
|
|
28
28
|
```
|
|
29
29
|
|
|
30
30
|
</TabItem>
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
title: 完整使用 Model
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
-
上一章节中,我们初步引入**客户端应用架构**,从【 视图组件 】中拆分出【 业务模型(Model)】,`
|
|
5
|
+
上一章节中,我们初步引入**客户端应用架构**,从【 视图组件 】中拆分出【 业务模型(Model)】,`page.tsx` 中不再包含 UI 无关的业务逻辑实现细节,只需要使用 Model,就能实现同样的功能。
|
|
6
6
|
|
|
7
|
-
这一章节中,我们要进一步利用 Model 中实现的业务逻辑,让 `
|
|
7
|
+
这一章节中,我们要进一步利用 Model 中实现的业务逻辑,让 `archived/page.ts` 也从 BFF 获取数据,实现 Archive 按钮,点击按钮能把联系人归档,只显示在 Archives 列表里,不显示在 All 列表里。
|
|
8
8
|
|
|
9
9
|
先改造 `Item` 组件,增加 Archive 按钮的交互实现:
|
|
10
10
|
|
|
11
|
-
```tsx title="src/contacts/components/Item/index.tsx"
|
|
11
|
+
```tsx title="src/contacts/routes/components/Item/index.tsx"
|
|
12
12
|
import Avatar from '../Avatar';
|
|
13
13
|
|
|
14
14
|
type InfoProps = {
|
|
@@ -42,7 +42,8 @@ const Item = ({
|
|
|
42
42
|
archived
|
|
43
43
|
? 'bg-gray-400 cursor-default'
|
|
44
44
|
: 'bg-blue-500 hover:bg-blue-700'
|
|
45
|
-
}`}
|
|
45
|
+
}`}
|
|
46
|
+
>
|
|
46
47
|
{archived ? 'Archived' : 'Archive'}
|
|
47
48
|
</button>
|
|
48
49
|
</div>
|
|
@@ -53,9 +54,9 @@ const Item = ({
|
|
|
53
54
|
export default Item;
|
|
54
55
|
```
|
|
55
56
|
|
|
56
|
-
|
|
57
|
+
两个页面需要共用同一套状态(联系人列表数据、联系人是否被归档),并且由于 Archives 列表和 All 列表都可能是第一屏页面(从不同 URL 访问),这两个组件都需要包含加载初始数据的逻辑(如果客户端没有联系人列表数据,就请求 BFF),所以这类两个组件公用的实现逻辑应该合并到一起:
|
|
57
58
|
|
|
58
|
-
|
|
59
|
+
我们创建一个新的 `Contacts` 组件:
|
|
59
60
|
|
|
60
61
|
import Tabs from '@theme/Tabs';
|
|
61
62
|
import TabItem from '@theme/TabItem';
|
|
@@ -64,18 +65,16 @@ import TabItem from '@theme/TabItem';
|
|
|
64
65
|
<TabItem value="macOS" label="macOS" default>
|
|
65
66
|
|
|
66
67
|
```bash
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
touch src/contacts/components/Contacts/index.tsx
|
|
68
|
+
mkdir -p src/contacts/routes/components/Contacts/
|
|
69
|
+
touch src/contacts/routes/components/Contacts/index.tsx
|
|
70
70
|
```
|
|
71
71
|
|
|
72
72
|
</TabItem>
|
|
73
73
|
<TabItem value="Windows" label="Windows">
|
|
74
74
|
|
|
75
75
|
```powershell
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
ni src/contacts/components/Contacts/index.tsx
|
|
76
|
+
mkdir -p src/contacts/routes/components/Contacts/
|
|
77
|
+
ni src/contacts/routes/components/Contacts/index.tsx
|
|
79
78
|
```
|
|
80
79
|
|
|
81
80
|
</TabItem>
|
|
@@ -83,7 +82,7 @@ ni src/contacts/components/Contacts/index.tsx
|
|
|
83
82
|
|
|
84
83
|
修改`components/Contacts/index.tsx` ,内容如下:
|
|
85
84
|
|
|
86
|
-
```tsx title="src/contacts/components/Contacts/index.tsx"
|
|
85
|
+
```tsx title="src/contacts/routes/components/Contacts/index.tsx"
|
|
87
86
|
import { useEffect } from 'react';
|
|
88
87
|
import { useLocalModel } from '@modern-js/runtime/model';
|
|
89
88
|
import { List } from 'antd';
|
|
@@ -128,57 +127,39 @@ const Contacts = ({ source }: { source: 'archived' | 'items' }) => {
|
|
|
128
127
|
export default Contacts;
|
|
129
128
|
```
|
|
130
129
|
|
|
131
|
-
|
|
132
|
-
由于 computed 功能还未提供,这里先在组件里将传入的数据做预处理。
|
|
133
|
-
:::
|
|
130
|
+
最后改造 `page.tsx` 和 `archived/page.ts`,利用 Contacts 实现 Archives 列表和 All 列表:
|
|
134
131
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
import { useState } from 'react';
|
|
139
|
-
import { Radio, RadioChangeEvent } from 'antd';
|
|
140
|
-
import { Route, useHistory } from '@modern-js/runtime/router';
|
|
141
|
-
import { Helmet } from '@modern-js/runtime/head';
|
|
132
|
+
```tsx title="src/contacts/page.tsx"
|
|
133
|
+
import Contacts from './components/Contacts';
|
|
134
|
+
import 'ladda/dist/ladda.min.css';
|
|
142
135
|
import 'tailwindcss/base.css';
|
|
143
136
|
import 'tailwindcss/components.css';
|
|
144
137
|
import 'tailwindcss/utilities.css';
|
|
145
138
|
import './styles/utils.css';
|
|
146
|
-
import Contacts from './components/Contacts';
|
|
147
139
|
|
|
148
|
-
function
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
140
|
+
function Index() {
|
|
141
|
+
return (
|
|
142
|
+
<div className="container lg mx-auto">
|
|
143
|
+
<Contacts source="items" />
|
|
144
|
+
</div>
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export default Index;
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
```tsx title="src/contacts/archived/page.tsx"
|
|
152
|
+
import Contacts from './components/Contacts';
|
|
156
153
|
|
|
154
|
+
function Index() {
|
|
157
155
|
return (
|
|
158
156
|
<div className="container lg mx-auto">
|
|
159
|
-
<
|
|
160
|
-
<Radio.Group onChange={handleSetList} value={currentList}>
|
|
161
|
-
<Radio value="/">All</Radio>
|
|
162
|
-
<Radio value="/archives">Archives</Radio>
|
|
163
|
-
</Radio.Group>
|
|
164
|
-
</div>
|
|
165
|
-
<Route path="/" exact={true}>
|
|
166
|
-
<Helmet>
|
|
167
|
-
<title>All</title>
|
|
168
|
-
</Helmet>
|
|
169
|
-
<Contacts source="items" />
|
|
170
|
-
</Route>
|
|
171
|
-
<Route path="/archives" exact={true}>
|
|
172
|
-
<Helmet>
|
|
173
|
-
<title>Archives</title>
|
|
174
|
-
</Helmet>
|
|
175
|
-
<Contacts source="archived" />
|
|
176
|
-
</Route>
|
|
157
|
+
<Contacts source="archived" />
|
|
177
158
|
</div>
|
|
178
159
|
);
|
|
179
160
|
}
|
|
180
161
|
|
|
181
|
-
export default
|
|
162
|
+
export default Index;
|
|
182
163
|
```
|
|
183
164
|
|
|
184
165
|
执行 `pnpm run dev`,访问 `http://localhost:8080/contacts/`,点击 Archive 按钮后,可以看到按钮置灰:
|
|
@@ -189,22 +170,7 @@ export default App;
|
|
|
189
170
|
|
|
190
171
|

|
|
191
172
|
|
|
192
|
-
出现这个问题的原因是,我们继续沿用了上一节的 `useLocalModel` API 来使用 Model,状态被保存到了组件内部的 state 里,而 `All` 列表和 `Archives` 列表中分别调用的 `Contacts`
|
|
193
|
-
|
|
194
|
-
```tsx title="src/contacts/App.tsx"
|
|
195
|
-
<Route path="/" exact={true}>
|
|
196
|
-
<Helmet>
|
|
197
|
-
<title>All</title>
|
|
198
|
-
</Helmet>
|
|
199
|
-
<Contacts source="items" />
|
|
200
|
-
</Route>
|
|
201
|
-
<Route path="/archives" exact={true}>
|
|
202
|
-
<Helmet>
|
|
203
|
-
<title>Archives</title>
|
|
204
|
-
</Helmet>
|
|
205
|
-
<Contacts source="archived" />
|
|
206
|
-
</Route>
|
|
207
|
-
```
|
|
173
|
+
出现这个问题的原因是,我们继续沿用了上一节的 `useLocalModel` API 来使用 Model,状态被保存到了组件内部的 state 里,而 `All` 列表和 `Archives` 列表中分别调用的 `Contacts` 组件,是两个各自独立的组件.
|
|
208
174
|
|
|
209
175
|
所以它们有各自独立的内部 state,互相不共享状态,渲染 `Archives` 列表的时候,`items` 仍然是初始状态。
|
|
210
176
|
|
|
@@ -215,7 +181,7 @@ export default App;
|
|
|
215
181
|
修改 `components/Contacts/index.tsx` 的内容:
|
|
216
182
|
|
|
217
183
|
|
|
218
|
-
```tsx title="src/contacts/components/Contacts/index.tsx"
|
|
184
|
+
```tsx title="src/contacts/routes/components/Contacts/index.tsx"
|
|
219
185
|
import { useEffect } from 'react';
|
|
220
186
|
import { useModel } from '@modern-js/runtime/model';
|
|
221
187
|
import { List } from 'antd';
|
|
@@ -19,9 +19,9 @@ import TabItem from '@theme/TabItem';
|
|
|
19
19
|
<TabItem value="macOS" label="macOS" default>
|
|
20
20
|
|
|
21
21
|
```bash
|
|
22
|
-
mkdir -p src/contacts/containers/
|
|
23
|
-
mv src/contacts/components/Contacts/index.tsx src/contacts/containers/Contacts.tsx
|
|
24
|
-
rm -r src/contacts/components/Contacts/
|
|
22
|
+
mkdir -p src/contacts/routes/containers/
|
|
23
|
+
mv src/contacts/routes/components/Contacts/index.tsx src/contacts/routes/containers/Contacts.tsx
|
|
24
|
+
rm -r src/contacts/routes/components/Contacts/
|
|
25
25
|
```
|
|
26
26
|
|
|
27
27
|
</TabItem>
|
|
@@ -43,7 +43,7 @@ import Item from '../components/Item';
|
|
|
43
43
|
import contacts from '../models/contacts';
|
|
44
44
|
```
|
|
45
45
|
|
|
46
|
-
修改 `
|
|
46
|
+
修改 `page.tsx` 和 `archives/page.tsx` 的代码:
|
|
47
47
|
|
|
48
48
|
```tsx
|
|
49
49
|
import Contacts from './containers/Contacts';
|
|
@@ -53,45 +53,48 @@ import Contacts from './containers/Contacts';
|
|
|
53
53
|
|
|
54
54
|
```md
|
|
55
55
|
.
|
|
56
|
-
├── .
|
|
57
|
-
├── api/
|
|
58
|
-
│ ├── .eslintrc.json
|
|
59
|
-
│ └── contacts.ts
|
|
60
|
-
├── src/
|
|
61
|
-
│ ├── contacts/
|
|
62
|
-
│ │ ├── components/
|
|
63
|
-
│ │ │ ├── Avatar/
|
|
64
|
-
│ │ │ │ ├── index.stories.tsx
|
|
65
|
-
│ │ │ │ └── index.tsx
|
|
66
|
-
│ │ │ └── Item/
|
|
67
|
-
│ │ │ ├── index.test.tsx
|
|
68
|
-
│ │ │ └── index.tsx
|
|
69
|
-
│ │ ├── containers/
|
|
70
|
-
│ │ │ └── Contacts.tsx
|
|
71
|
-
│ │ ├── models/
|
|
72
|
-
│ │ │ ├── contacts.test.ts
|
|
73
|
-
│ │ │ └── contacts.ts
|
|
74
|
-
│ │ ├── styles/
|
|
75
|
-
│ │ │ └── utils.css
|
|
76
|
-
│ │ ├── App.css
|
|
77
|
-
│ │ └── App.tsx
|
|
78
|
-
│ ├── landing-page/
|
|
79
|
-
│ │ └── pages/
|
|
80
|
-
│ │ ├── comments/
|
|
81
|
-
│ │ │ └── [commentTitle]/
|
|
82
|
-
│ │ │ └── index.tsx
|
|
83
|
-
│ │ ├── _app.tsx
|
|
84
|
-
│ │ ├── docs.tsx
|
|
85
|
-
│ │ └── index.tsx
|
|
86
|
-
│ ├── .eslintrc.json
|
|
87
|
-
│ └── modern-app-env.d.ts
|
|
88
|
-
├── .editorconfig
|
|
56
|
+
├── .eslintrc.js
|
|
89
57
|
├── .gitignore
|
|
58
|
+
├── .husky
|
|
90
59
|
├── .npmrc
|
|
91
60
|
├── .nvmrc
|
|
61
|
+
├── .prettierrc
|
|
62
|
+
├── .vscode
|
|
92
63
|
├── README.md
|
|
64
|
+
├── api
|
|
65
|
+
│ └── contacts.ts
|
|
66
|
+
├── modern.config.ts
|
|
93
67
|
├── package.json
|
|
94
68
|
├── pnpm-lock.yaml
|
|
69
|
+
├── src
|
|
70
|
+
│ ├── .eslintrc.js
|
|
71
|
+
│ ├── contacts
|
|
72
|
+
│ │ └── routes
|
|
73
|
+
│ │ ├── archives
|
|
74
|
+
│ │ │ └── page.tsx
|
|
75
|
+
│ │ ├── components
|
|
76
|
+
│ │ │ ├── Avatar
|
|
77
|
+
│ │ │ │ ├── index.stories.tsx
|
|
78
|
+
│ │ │ │ └── index.tsx
|
|
79
|
+
│ │ │ └── Item
|
|
80
|
+
│ │ │ ├── index.test.tsx
|
|
81
|
+
│ │ │ └── index.tsx
|
|
82
|
+
│ │ ├── containers
|
|
83
|
+
│ │ │ └── Contacts.tsx
|
|
84
|
+
│ │ ├── index.css
|
|
85
|
+
│ │ ├── layout.tsx
|
|
86
|
+
│ │ ├── models
|
|
87
|
+
│ │ │ ├── contacts.test.ts
|
|
88
|
+
│ │ │ └── contacts.ts
|
|
89
|
+
│ │ ├── page.tsx
|
|
90
|
+
│ │ └── styles
|
|
91
|
+
│ │ └── utils.css
|
|
92
|
+
│ ├── landing-page
|
|
93
|
+
│ │ └── routes
|
|
94
|
+
│ │ ├── index.css
|
|
95
|
+
│ │ ├── layout.tsx
|
|
96
|
+
│ │ └── page.tsx
|
|
97
|
+
│ └── modern-app-env.d.ts
|
|
95
98
|
└── tsconfig.json
|
|
96
99
|
```
|
|
97
100
|
|
|
@@ -8,10 +8,12 @@ title: 使用 Loader
|
|
|
8
8
|
|
|
9
9
|
可以在当前项目中开启 [SSR](/docs/configure/app/server/ssr),看下这种效果。
|
|
10
10
|
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
```js
|
|
12
|
+
export default defineConfig({
|
|
13
|
+
server: {
|
|
14
|
+
ssr: true,
|
|
15
|
+
},
|
|
16
|
+
});
|
|
15
17
|
```
|
|
16
18
|
|
|
17
19
|
执行 `pnpm run dev`,在 devtools 的 network 面板里查看 HTML 请求的 Preview 面板,可以看到 SSR 的渲染结果只有导航栏和 Pending... 字符,并没有联系人数据:
|
|
@@ -13,14 +13,14 @@ import TabItem from '@theme/TabItem';
|
|
|
13
13
|
<TabItem value="macOS" label="macOS" default>
|
|
14
14
|
|
|
15
15
|
```bash
|
|
16
|
-
touch src/contacts/containers/contacts.test.tsx
|
|
16
|
+
touch src/contacts/routes/containers/contacts.test.tsx
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
</TabItem>
|
|
20
20
|
<TabItem value="Windows" label="Windows">
|
|
21
21
|
|
|
22
22
|
```powershell
|
|
23
|
-
ni src/contacts/containers/contacts.test.tsx
|
|
23
|
+
ni src/contacts/routes/containers/contacts.test.tsx
|
|
24
24
|
```
|
|
25
25
|
|
|
26
26
|
</TabItem>
|
|
@@ -31,7 +31,7 @@ Modern.js 能为开发者提供极致的**开发体验(Development Experience
|
|
|
31
31
|
- 🏠 **一体化**:开发与生产环境 Web Server 唯一,CSR 和 SSR 同构开发,函数即接口的 API 服务调用。
|
|
32
32
|
- 📦 **开箱即用**:默认 TS 支持,内置构建、ESLint、调试工具,全功能可测试。
|
|
33
33
|
- 🌏 **周边生态**:自研状态管理、微前端、模块打包、Monorepo 方案等周边需求。
|
|
34
|
-
- 🕸
|
|
34
|
+
- 🕸 **多种路由模式**:包含自控路由、基于文件约定的路由(嵌套路由)等。
|
|
35
35
|
- 🚀 **独立构建核心**:支持多种打包工具,深度优化构建产物。
|
|
36
36
|
|
|
37
37
|
## 下一步
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
sidebar_position: 1
|
|
3
|
-
title: Default Alias
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
Modern.js recommend referring to the source code by alias, which contains 3 default aliases:
|
|
7
|
-
- `@/`: the file under the project root directory `src/* `.
|
|
8
|
-
- `@api/`: the file under the `api/*` in the project root directory (you need to enable the BFF first).
|
|
9
|
-
- `@shared/`: the file under the project root directory `shared/* `.
|
|
10
|
-
|
|
11
|
-
:::tip
|
|
12
|
-
In addition, developers can customize aliases in modern.config.js, see [Aliases](/docs/configure/app/source/alias) for detail.
|
|
13
|
-
:::
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
## Example
|
|
17
|
-
|
|
18
|
-
The following example shows how to reference a function by default alias.
|
|
19
|
-
|
|
20
|
-
```tsx
|
|
21
|
-
import { hello } from '@/common/utils';
|
|
22
|
-
|
|
23
|
-
hello();
|
|
24
|
-
```
|
|
25
|
-
A reference to `@/common/utils` is equal to a reference to `src/common/utils`.
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
sidebar_position: 1
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
# 概览
|
|
6
|
-
|
|
7
|
-
Modern.js 的基础的插件系统中主要分为三个部分: Hook 模型(Pipeline、Workflow、Waterfall)、 Hook 模型的管理器(Manager),上下文共享机制。
|
|
8
|
-
|
|
9
|
-
其中的 Hook 模型是用于管理运行一系列相同模型(形状)函数的管理工具,目前提供了三个大类,7个小类:
|
|
10
|
-
|
|
11
|
-
- Pipeline
|
|
12
|
-
- Sync
|
|
13
|
-
- Async
|
|
14
|
-
- Waterfall
|
|
15
|
-
- Sync
|
|
16
|
-
- Async
|
|
17
|
-
- Workflow
|
|
18
|
-
- Sync
|
|
19
|
-
- Async
|
|
20
|
-
- Parallel(Async)
|
|
21
|
-
|
|
22
|
-
它们之间的区别是他们所管理的函数的运行模式的不同。不同的地方会在下面具体分析介绍。
|
|
23
|
-
|
|
24
|
-
Hook 模型的管理器(Manager),顾名思义就是用来管理上面提到的那些 Hook 模型,添加至同一个 Manager 可以使用同一个 Runner 对象(包含所有 Hook 的执行函数)来运行,也共享同一个上下文环境。而 Modern.js 的基础插件系统中的插件就是针对 Manager 来说的,是一个拥有属性、插件 Hook 函数的对象。
|
|
25
|
-
|
|
26
|
-
基于上面的工具(Hook 模型 + Manager),在 Modern.js 中主要构建了三套插件模型: CLI、Runtime、Server。其中 CLI 是 Modern.js 中主要的运行流程控制模型,Modern.js 中的各种工程方案(应用工程方案、模块工程方案、Monorepo 工程方案)都是主要通过这一套模型运行的。而 Runtime 则主要负责的是 React 路由组件和元素的处理(Component 和 Element)和渲染(包括服务器端渲染和客户端渲染)。而 Server 则是针对 Server 运行时的这个阶段的生命周期运行和特殊信息收集。其中 Runtime 和 Server 的运行都是在 CLI 中触发的。
|