@modern-js/main-doc 2.69.4 → 3.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/en/{_meta.json → _nav.json} +5 -1
- package/docs/en/apis/app/commands.mdx +2 -3
- package/docs/en/apis/app/hooks/src/entry.mdx +1 -5
- package/docs/en/apis/app/hooks/src/entry.server.mdx +4 -5
- package/docs/en/apis/app/hooks/src/routes.mdx +2 -2
- package/docs/en/apis/app/runtime/_meta.json +0 -18
- package/docs/en/apis/app/runtime/bff/use-hono-context.mdx +2 -2
- package/docs/en/apis/app/runtime/router/router.mdx +1 -1
- package/docs/en/apis/app/runtime/utility/css-in-js.mdx +3 -2
- package/docs/en/community/blog/v2-release-note.mdx +0 -2
- package/docs/en/community/contributing-guide.mdx +10 -12
- package/docs/en/components/bff-upload.mdx +16 -12
- package/docs/en/components/build-output.mdx +45 -0
- package/docs/en/components/debug-app.mdx +1 -1
- package/docs/en/components/enable-bff-caution.mdx +2 -2
- package/docs/en/components/enable-bff.mdx +38 -8
- package/docs/en/components/enable-ssg.mdx +48 -0
- package/docs/en/components/entry-scan-logic.mdx +7 -0
- package/docs/en/components/init-app.mdx +40 -17
- package/docs/en/components/international/install-command.mdx +9 -0
- package/docs/en/components/international/introduce.mdx +2 -0
- package/docs/en/components/module-federation.mdx +4 -4
- package/docs/en/components/new-entry-tooltip.mdx +0 -0
- package/docs/en/components/nodeVersion.mdx +2 -6
- package/docs/en/components/prerequisites.mdx +1 -1
- package/docs/en/components/ua-polyfill.mdx +16 -12
- package/docs/en/components/upgrade-browserslist.mdx +0 -0
- package/docs/en/configure/_meta.json +7 -8
- package/docs/en/configure/app/bff/cross-project.mdx +24 -0
- package/docs/en/configure/app/dev/lazy-compilation.mdx +45 -0
- package/docs/en/configure/app/dev/server.mdx +103 -0
- package/docs/en/configure/app/dev/setup-middlewares.mdx +4 -22
- package/docs/en/configure/app/html/app-icon.mdx +1 -23
- package/docs/en/configure/app/output/inline-scripts.mdx +1 -1
- package/docs/en/configure/app/output/override-browserslist.mdx +6 -4
- package/docs/en/configure/app/output/source-map.mdx +6 -3
- package/docs/en/configure/app/output/ssg.mdx +12 -43
- package/docs/en/configure/app/output/ssgByEntries.mdx +93 -0
- package/docs/en/configure/app/performance/build-cache.mdx +0 -4
- package/docs/en/configure/app/resolve/alias-strategy.mdx +14 -0
- package/docs/en/configure/app/resolve/alias.mdx +13 -0
- package/docs/en/configure/app/resolve/condition-names.mdx +18 -0
- package/docs/en/configure/app/resolve/dedupe.mdx +13 -0
- package/docs/en/configure/app/resolve/extensions.mdx +18 -0
- package/docs/en/configure/app/runtime/0-intro.mdx +2 -51
- package/docs/en/configure/app/security/check-syntax.mdx +1 -1
- package/docs/en/configure/app/server/port.mdx +1 -21
- package/docs/en/configure/app/server/rsc.mdx +30 -0
- package/docs/en/configure/app/server/ssr.mdx +20 -9
- package/docs/en/configure/app/source/decorators.mdx +4 -2
- package/docs/en/configure/app/source/entries.mdx +0 -2
- package/docs/en/configure/app/source/main-entry-name.mdx +4 -4
- package/docs/en/configure/app/source/transform-import.mdx +1 -59
- package/docs/en/configure/app/tools/bundler-chain.mdx +5 -5
- package/docs/en/configure/app/tools/css-extract.mdx +1 -1
- package/docs/en/configure/app/tools/dev-server.mdx +14 -248
- package/docs/en/configure/app/tools/html-plugin.mdx +3 -3
- package/docs/en/configure/app/tools/lightningcss-loader.mdx +0 -1
- package/docs/en/configure/app/tools/swc.mdx +1 -43
- package/docs/en/configure/app/usage.mdx +7 -17
- package/docs/en/guides/_meta.json +1 -2
- package/docs/en/guides/advanced-features/_meta.json +6 -0
- package/docs/en/guides/advanced-features/bff/cross-project.mdx +1 -7
- package/docs/en/guides/advanced-features/bff/extend-server.mdx +18 -3
- package/docs/en/guides/advanced-features/bff/frameworks.mdx +1 -1
- package/docs/en/guides/advanced-features/bff/function.mdx +2 -6
- package/docs/en/guides/advanced-features/bff/sdk.mdx +3 -3
- package/docs/en/guides/advanced-features/build-performance.mdx +23 -26
- package/docs/en/guides/advanced-features/compatibility.mdx +53 -9
- package/docs/en/guides/advanced-features/international/_meta.json +11 -0
- package/docs/en/guides/advanced-features/international/advanced.mdx +193 -0
- package/docs/en/guides/advanced-features/international/api.mdx +400 -0
- package/docs/en/guides/advanced-features/international/basic.mdx +417 -0
- package/docs/en/guides/advanced-features/international/best-practices.mdx +135 -0
- package/docs/en/guides/advanced-features/international/configuration.mdx +437 -0
- package/docs/en/guides/advanced-features/international/locale-detection.mdx +276 -0
- package/docs/en/guides/advanced-features/international/quick-start.mdx +154 -0
- package/docs/en/guides/advanced-features/international/resource-loading.mdx +417 -0
- package/docs/en/guides/advanced-features/international/routing.mdx +212 -0
- package/docs/en/guides/advanced-features/international.mdx +37 -0
- package/docs/en/guides/advanced-features/low-level.mdx +21 -16
- package/docs/en/guides/advanced-features/page-performance/code-split.mdx +4 -4
- package/docs/en/guides/advanced-features/page-performance/inline-assets.mdx +4 -4
- package/docs/en/guides/advanced-features/page-performance/optimize-bundle.mdx +7 -21
- package/docs/en/guides/advanced-features/page-performance/react-compiler.mdx +1 -8
- package/docs/en/guides/advanced-features/rspack-start.mdx +2 -22
- package/docs/en/guides/advanced-features/server-monitor/logger.mdx +0 -4
- package/docs/en/guides/advanced-features/server-monitor/monitors.mdx +62 -34
- package/docs/en/guides/advanced-features/web-server.mdx +82 -299
- package/docs/en/guides/basic-features/_meta.json +6 -1
- package/docs/en/guides/basic-features/css/css-in-js.mdx +46 -11
- package/docs/en/guides/basic-features/css/css-modules.mdx +5 -17
- package/docs/en/guides/basic-features/css/css.mdx +3 -3
- package/docs/en/guides/basic-features/css/tailwindcss.mdx +5 -89
- package/docs/en/guides/basic-features/data/data-cache.mdx +5 -1
- package/docs/en/guides/basic-features/data/data-fetch.mdx +4 -4
- package/docs/en/guides/basic-features/data/data-write.mdx +2 -2
- package/docs/en/guides/basic-features/debug/mock.mdx +4 -1
- package/docs/en/guides/basic-features/debug/proxy.mdx +0 -8
- package/docs/en/guides/basic-features/debug/rsdoctor.mdx +5 -5
- package/docs/en/guides/basic-features/deploy.mdx +25 -18
- package/docs/en/guides/basic-features/env-vars.mdx +1 -1
- package/docs/en/guides/basic-features/html.mdx +1 -1
- package/docs/en/guides/basic-features/output-files.mdx +3 -3
- package/docs/en/guides/basic-features/render/_meta.json +1 -1
- package/docs/en/guides/basic-features/render/before-render.mdx +16 -23
- package/docs/en/guides/basic-features/render/overview.mdx +51 -0
- package/docs/en/guides/basic-features/render/rsc.mdx +394 -0
- package/docs/en/guides/basic-features/render/ssg.mdx +26 -62
- package/docs/en/guides/basic-features/render/ssr-cache.mdx +6 -6
- package/docs/en/guides/basic-features/render/ssr.mdx +31 -31
- package/docs/en/guides/basic-features/render/streaming-ssr.mdx +29 -9
- package/docs/en/guides/basic-features/routes/_meta.json +1 -0
- package/docs/en/guides/basic-features/routes/config-routes.mdx +427 -0
- package/docs/en/guides/basic-features/{routes.mdx → routes/routes.mdx} +7 -110
- package/docs/en/guides/basic-features/static-assets/json-files.mdx +21 -3
- package/docs/en/guides/basic-features/static-assets.mdx +2 -2
- package/docs/en/guides/concept/builder.mdx +24 -9
- package/docs/en/guides/concept/entries.mdx +139 -147
- package/docs/en/guides/get-started/glossary.mdx +0 -18
- package/docs/en/guides/get-started/introduction.mdx +1 -4
- package/docs/en/guides/get-started/quick-start.mdx +8 -73
- package/docs/en/guides/get-started/tech-stack.mdx +7 -25
- package/docs/en/guides/get-started/upgrade.mdx +30 -23
- package/docs/en/guides/topic-detail/_meta.json +0 -12
- package/docs/en/guides/topic-detail/module-federation/_meta.json +1 -1
- package/docs/en/guides/topic-detail/module-federation/application.mdx +16 -15
- package/docs/en/guides/topic-detail/module-federation/i18n.mdx +670 -0
- package/docs/en/guides/topic-detail/module-federation/introduce.mdx +5 -4
- package/docs/en/guides/topic-detail/module-federation/ssr.mdx +50 -2
- package/docs/en/guides/topic-detail/module-federation/usage.mdx +10 -30
- package/docs/en/guides/troubleshooting/builder.mdx +3 -82
- package/docs/en/guides/troubleshooting/cli.mdx +6 -30
- package/docs/en/guides/troubleshooting/dependencies.mdx +22 -22
- package/docs/en/plugin/cli-plugins/api.mdx +4 -5
- package/docs/en/plugin/cli-plugins/migration.mdx +33 -48
- package/docs/en/plugin/introduction.mdx +39 -27
- package/docs/en/plugin/official/_meta.json +0 -5
- package/docs/en/plugin/official/cli-plugins/_meta.json +1 -1
- package/docs/en/plugin/official/cli-plugins/plugin-styled-components.mdx +5 -0
- package/docs/en/plugin/official/cli-plugins.mdx +0 -2
- package/docs/en/plugin/plugin-system.mdx +68 -61
- package/docs/en/plugin/runtime-plugins/api.mdx +62 -59
- package/docs/en/plugin/runtime-plugins/migration.mdx +29 -20
- package/docs/en/tutorials/_meta.json +0 -10
- package/docs/en/tutorials/examples/csr-auth.mdx +1 -1
- package/docs/en/tutorials/foundations/introduction.mdx +9 -25
- package/docs/zh/{_meta.json → _nav.json} +10 -6
- package/docs/zh/apis/app/commands.mdx +2 -3
- package/docs/zh/apis/app/hooks/src/entry.mdx +1 -5
- package/docs/zh/apis/app/hooks/src/entry.server.mdx +4 -5
- package/docs/zh/apis/app/hooks/src/routes.mdx +2 -2
- package/docs/zh/apis/app/runtime/_meta.json +0 -18
- package/docs/zh/apis/app/runtime/bff/use-hono-context.mdx +2 -2
- package/docs/zh/apis/app/runtime/utility/css-in-js.mdx +3 -2
- package/docs/zh/community/blog/v2-release-note.mdx +0 -2
- package/docs/zh/community/contributing-guide.mdx +10 -12
- package/docs/zh/components/auto-upgrade.mdx +0 -0
- package/docs/zh/components/bff-upload.mdx +8 -5
- package/docs/zh/components/build-output.mdx +45 -0
- package/docs/zh/components/debug-app.mdx +1 -1
- package/docs/zh/components/enable-bff-caution.mdx +1 -1
- package/docs/zh/components/enable-bff.mdx +37 -8
- package/docs/zh/components/enable-ssg.mdx +47 -0
- package/docs/zh/components/entry-scan-logic.mdx +7 -0
- package/docs/zh/components/init-app.mdx +40 -18
- package/docs/zh/components/international/install-command.mdx +8 -0
- package/docs/zh/components/international/introduce.mdx +2 -0
- package/docs/zh/components/international/platform-support.mdx +0 -0
- package/docs/zh/components/module-federation.mdx +4 -4
- package/docs/zh/components/new-entry-tooltip.mdx +0 -0
- package/docs/zh/components/nodeVersion.mdx +3 -7
- package/docs/zh/components/prerequisites.mdx +1 -1
- package/docs/zh/components/self-route-example.mdx +3 -3
- package/docs/zh/components/ua-polyfill.mdx +11 -6
- package/docs/zh/components/upgrade-browserslist.mdx +0 -0
- package/docs/zh/configure/_meta.json +7 -8
- package/docs/zh/configure/app/bff/cross-project.mdx +24 -0
- package/docs/zh/configure/app/dev/lazy-compilation.mdx +44 -0
- package/docs/zh/configure/app/dev/server.mdx +104 -0
- package/docs/zh/configure/app/dev/setup-middlewares.mdx +4 -23
- package/docs/zh/configure/app/html/app-icon.mdx +1 -23
- package/docs/zh/configure/app/output/inline-scripts.mdx +1 -1
- package/docs/zh/configure/app/output/override-browserslist.mdx +3 -3
- package/docs/zh/configure/app/output/source-map.mdx +10 -3
- package/docs/zh/configure/app/output/ssg.mdx +13 -45
- package/docs/zh/configure/app/output/ssgByEntries.mdx +94 -0
- package/docs/zh/configure/app/performance/build-cache.mdx +0 -4
- package/docs/zh/configure/app/resolve/alias-strategy.mdx +14 -0
- package/docs/zh/configure/app/resolve/alias.mdx +13 -0
- package/docs/zh/configure/app/resolve/condition-names.mdx +18 -0
- package/docs/zh/configure/app/resolve/dedupe.mdx +14 -0
- package/docs/zh/configure/app/resolve/extensions.mdx +18 -0
- package/docs/zh/configure/app/runtime/0-intro.mdx +2 -53
- package/docs/zh/configure/app/security/check-syntax.mdx +1 -1
- package/docs/zh/configure/app/server/port.mdx +2 -21
- package/docs/zh/configure/app/server/rsc.mdx +30 -0
- package/docs/zh/configure/app/server/ssr.mdx +21 -11
- package/docs/zh/configure/app/source/decorators.mdx +4 -4
- package/docs/zh/configure/app/source/entries.mdx +0 -2
- package/docs/zh/configure/app/source/main-entry-name.mdx +4 -4
- package/docs/zh/configure/app/source/transform-import.mdx +1 -59
- package/docs/zh/configure/app/tools/bundler-chain.mdx +6 -6
- package/docs/zh/configure/app/tools/css-extract.mdx +1 -1
- package/docs/zh/configure/app/tools/dev-server.mdx +14 -248
- package/docs/zh/configure/app/tools/html-plugin.mdx +3 -2
- package/docs/zh/configure/app/tools/lightningcss-loader.mdx +0 -1
- package/docs/zh/configure/app/tools/swc.mdx +1 -43
- package/docs/zh/configure/app/usage.mdx +8 -18
- package/docs/zh/guides/_meta.json +5 -1
- package/docs/zh/guides/advanced-features/_meta.json +6 -1
- package/docs/zh/guides/advanced-features/bff/cross-project.mdx +8 -16
- package/docs/zh/guides/advanced-features/bff/extend-server.mdx +25 -8
- package/docs/zh/guides/advanced-features/bff/frameworks.mdx +1 -1
- package/docs/zh/guides/advanced-features/bff/function.mdx +7 -12
- package/docs/zh/guides/advanced-features/bff/sdk.mdx +4 -4
- package/docs/zh/guides/advanced-features/build-performance.mdx +23 -30
- package/docs/zh/guides/advanced-features/compatibility.mdx +44 -0
- package/docs/zh/guides/advanced-features/international/_meta.json +11 -0
- package/docs/zh/guides/advanced-features/international/advanced.mdx +193 -0
- package/docs/zh/guides/advanced-features/international/api.mdx +400 -0
- package/docs/zh/guides/advanced-features/international/basic.mdx +416 -0
- package/docs/zh/guides/advanced-features/international/best-practices.mdx +135 -0
- package/docs/zh/guides/advanced-features/international/configuration.mdx +441 -0
- package/docs/zh/guides/advanced-features/international/locale-detection.mdx +304 -0
- package/docs/zh/guides/advanced-features/international/quick-start.mdx +149 -0
- package/docs/zh/guides/advanced-features/international/resource-loading.mdx +417 -0
- package/docs/zh/guides/advanced-features/international/routing.mdx +212 -0
- package/docs/zh/guides/advanced-features/international.mdx +36 -0
- package/docs/zh/guides/advanced-features/low-level.mdx +21 -16
- package/docs/zh/guides/advanced-features/page-performance/code-split.mdx +3 -3
- package/docs/zh/guides/advanced-features/page-performance/inline-assets.mdx +4 -4
- package/docs/zh/guides/advanced-features/page-performance/optimize-bundle.mdx +7 -21
- package/docs/zh/guides/advanced-features/page-performance/react-compiler.mdx +1 -8
- package/docs/zh/guides/advanced-features/server-monitor/logger.mdx +0 -4
- package/docs/zh/guides/advanced-features/server-monitor/monitors.mdx +63 -35
- package/docs/zh/guides/advanced-features/web-server.mdx +79 -300
- package/docs/zh/guides/basic-features/_meta.json +6 -1
- package/docs/zh/guides/basic-features/css/css-in-js.mdx +40 -5
- package/docs/zh/guides/basic-features/css/css-modules.mdx +6 -17
- package/docs/zh/guides/basic-features/css/css.mdx +2 -2
- package/docs/zh/guides/basic-features/css/tailwindcss.mdx +6 -90
- package/docs/zh/guides/basic-features/data/data-cache.mdx +8 -5
- package/docs/zh/guides/basic-features/data/data-fetch.mdx +6 -5
- package/docs/zh/guides/basic-features/data/data-write.mdx +4 -4
- package/docs/zh/guides/basic-features/debug/mock.mdx +4 -1
- package/docs/zh/guides/basic-features/debug/proxy.mdx +0 -8
- package/docs/zh/guides/basic-features/debug/rsdoctor.mdx +6 -6
- package/docs/zh/guides/basic-features/deploy.mdx +24 -20
- package/docs/zh/guides/basic-features/env-vars.mdx +1 -1
- package/docs/zh/guides/basic-features/html.mdx +2 -2
- package/docs/zh/guides/basic-features/output-files.mdx +3 -3
- package/docs/zh/guides/basic-features/render/_meta.json +1 -1
- package/docs/zh/guides/basic-features/render/before-render.mdx +17 -24
- package/docs/zh/guides/basic-features/render/overview.mdx +52 -0
- package/docs/zh/guides/basic-features/render/rsc.mdx +413 -0
- package/docs/zh/guides/basic-features/render/ssg.mdx +27 -69
- package/docs/zh/guides/basic-features/render/ssr-cache.mdx +5 -5
- package/docs/zh/guides/basic-features/render/ssr.mdx +34 -31
- package/docs/zh/guides/basic-features/render/streaming-ssr.mdx +34 -14
- package/docs/zh/guides/basic-features/routes/_meta.json +1 -0
- package/docs/zh/guides/basic-features/routes/config-routes.mdx +426 -0
- package/docs/zh/guides/basic-features/{routes.mdx → routes/routes.mdx} +8 -114
- package/docs/zh/guides/basic-features/static-assets/json-files.mdx +21 -3
- package/docs/zh/guides/basic-features/static-assets.mdx +2 -2
- package/docs/zh/guides/basic-features/testing/cypress.mdx +5 -5
- package/docs/zh/guides/basic-features/testing/jest.mdx +12 -12
- package/docs/zh/guides/concept/builder.mdx +24 -9
- package/docs/zh/guides/concept/entries.mdx +95 -92
- package/docs/zh/guides/get-started/glossary.mdx +0 -18
- package/docs/zh/guides/get-started/introduction.mdx +1 -5
- package/docs/zh/guides/get-started/quick-start.mdx +5 -72
- package/docs/zh/guides/get-started/tech-stack.mdx +8 -26
- package/docs/zh/guides/get-started/upgrade.mdx +30 -23
- package/docs/zh/guides/topic-detail/_meta.json +0 -12
- package/docs/zh/guides/topic-detail/module-federation/_meta.json +1 -1
- package/docs/zh/guides/topic-detail/module-federation/application.mdx +18 -16
- package/docs/zh/guides/topic-detail/module-federation/i18n.mdx +623 -0
- package/docs/zh/guides/topic-detail/module-federation/introduce.mdx +4 -4
- package/docs/zh/guides/topic-detail/module-federation/ssr.mdx +51 -5
- package/docs/zh/guides/topic-detail/module-federation/usage.mdx +11 -32
- package/docs/zh/guides/troubleshooting/builder.mdx +3 -84
- package/docs/zh/guides/troubleshooting/cli.mdx +6 -30
- package/docs/zh/guides/troubleshooting/dependencies.mdx +23 -23
- package/docs/zh/guides/upgrade/_meta.json +1 -0
- package/docs/zh/guides/upgrade/config.mdx +809 -0
- package/docs/zh/guides/upgrade/entry.mdx +463 -0
- package/docs/zh/guides/upgrade/other.md +90 -0
- package/docs/zh/guides/upgrade/overview.mdx +36 -0
- package/docs/zh/guides/upgrade/tailwindcss.mdx +130 -0
- package/docs/zh/guides/upgrade/web-server.md +93 -0
- package/docs/zh/plugin/cli-plugins/api.mdx +4 -5
- package/docs/zh/plugin/cli-plugins/migration.mdx +30 -45
- package/docs/zh/plugin/introduction.mdx +36 -24
- package/docs/zh/plugin/official/_meta.json +0 -5
- package/docs/zh/plugin/official/cli-plugins/_meta.json +1 -1
- package/docs/zh/plugin/official/cli-plugins/plugin-styled-components.mdx +5 -0
- package/docs/zh/plugin/official/cli-plugins.mdx +0 -2
- package/docs/zh/plugin/plugin-system.mdx +45 -42
- package/docs/zh/plugin/runtime-plugins/api.mdx +58 -56
- package/docs/zh/plugin/runtime-plugins/migration.mdx +26 -17
- package/docs/zh/tutorials/_meta.json +0 -10
- package/docs/zh/tutorials/examples/csr-auth.mdx +1 -1
- package/docs/zh/tutorials/foundations/introduction.mdx +8 -25
- package/i18n.json +0 -16
- package/package.json +12 -12
- package/rspress.config.ts +5 -8
- package/src/components/ContentCard/index.module.scss +11 -7
- package/src/components/ContentCard/index.tsx +1 -1
- package/src/components/FeatureLayout/index.module.css +1 -1
- package/src/components/Footer/index.tsx +2 -14
- package/src/components/Footer/styles.module.scss +5 -5
- package/src/components/ListCard/index.tsx +1 -1
- package/src/components/RandomMemberList/index.tsx +1 -1
- package/src/components/RsbuildLink/index.tsx +1 -1
- package/src/components/Sandpack/index.tsx +1 -1
- package/src/custom.scss +15 -0
- package/src/i18n/enUS.ts +2 -4
- package/src/i18n/index.ts +1 -1
- package/src/i18n/zhCN.ts +2 -4
- package/src/index.ts +2 -1
- package/src/pages/index.module.scss +59 -41
- package/src/pages/index.tsx +9 -24
- package/docs/en/apis/app/hooks/server/index_.mdx +0 -10
- package/docs/en/apis/app/hooks/src/index_.mdx +0 -38
- package/docs/en/apis/app/hooks/src/stories.mdx +0 -16
- package/docs/en/apis/app/runtime/app/define-config.mdx +0 -67
- package/docs/en/apis/app/runtime/core/bootstrap.mdx +0 -74
- package/docs/en/apis/app/runtime/core/create-app.mdx +0 -49
- package/docs/en/apis/app/runtime/core/use-loader.mdx +0 -89
- package/docs/en/apis/app/runtime/core/use-module-apps.mdx +0 -140
- package/docs/en/apis/app/runtime/core/use-runtime-context.mdx +0 -116
- package/docs/en/apis/app/runtime/model/Provider.mdx +0 -36
- package/docs/en/apis/app/runtime/model/auto-actions.mdx +0 -122
- package/docs/en/apis/app/runtime/model/connect.mdx +0 -146
- package/docs/en/apis/app/runtime/model/create-app.mdx +0 -75
- package/docs/en/apis/app/runtime/model/create-store.mdx +0 -61
- package/docs/en/apis/app/runtime/model/handle-effect.mdx +0 -107
- package/docs/en/apis/app/runtime/model/model_.mdx +0 -198
- package/docs/en/apis/app/runtime/model/use-local-model.mdx +0 -29
- package/docs/en/apis/app/runtime/model/use-model.mdx +0 -89
- package/docs/en/apis/app/runtime/model/use-static-model.mdx +0 -51
- package/docs/en/apis/app/runtime/model/use-store.mdx +0 -26
- package/docs/en/apis/app/runtime/ssr/pre-render.mdx +0 -96
- package/docs/en/apis/app/runtime/web-server/hook.mdx +0 -134
- package/docs/en/apis/app/runtime/web-server/middleware.mdx +0 -113
- package/docs/en/apis/app/runtime/web-server/unstable_middleware.mdx +0 -167
- package/docs/en/components/bff-proxy-path-rewrite.mdx +0 -16
- package/docs/en/components/bff-proxy-principle.mdx +0 -1
- package/docs/en/components/builder.mdx +0 -3
- package/docs/en/components/create-bff-api-app.mdx +0 -25
- package/docs/en/components/custom-router-micro-frontend.mdx +0 -40
- package/docs/en/components/enable-micro-frontend.mdx +0 -30
- package/docs/en/components/enableSwc.mdx +0 -17
- package/docs/en/components/global-proxy-config.mdx +0 -85
- package/docs/en/components/global-proxy.mdx +0 -29
- package/docs/en/components/package-manager.mdx +0 -11
- package/docs/en/components/reduck-notify.mdx +0 -27
- package/docs/en/components/reduck-tip.mdx +0 -8
- package/docs/en/configure/app/auto-load-plugin.mdx +0 -66
- package/docs/en/configure/app/deploy/microFrontend.mdx +0 -53
- package/docs/en/configure/app/dev/port.mdx +0 -25
- package/docs/en/configure/app/dev/proxy.mdx +0 -9
- package/docs/en/configure/app/experiments/lazy-compilation.mdx +0 -106
- package/docs/en/configure/app/html/disable-html-folder.mdx +0 -46
- package/docs/en/configure/app/html/favicon-by-entries.mdx +0 -36
- package/docs/en/configure/app/html/inject-by-entries.mdx +0 -36
- package/docs/en/configure/app/html/meta-by-entries.mdx +0 -48
- package/docs/en/configure/app/html/tags-by-entries.mdx +0 -44
- package/docs/en/configure/app/html/template-by-entries.mdx +0 -33
- package/docs/en/configure/app/html/template-parameters-by-entries.mdx +0 -35
- package/docs/en/configure/app/html/title-by-entries.mdx +0 -37
- package/docs/en/configure/app/output/css-module-local-ident-name.mdx +0 -21
- package/docs/en/configure/app/output/disable-css-extract.mdx +0 -16
- package/docs/en/configure/app/output/disable-filename-hash.mdx +0 -16
- package/docs/en/configure/app/output/disable-minimize.mdx +0 -14
- package/docs/en/configure/app/output/disable-node-polyfill.mdx +0 -22
- package/docs/en/configure/app/output/disable-source-map.mdx +0 -31
- package/docs/en/configure/app/output/enable-asset-fallback.mdx +0 -36
- package/docs/en/configure/app/output/enable-inline-scripts.mdx +0 -22
- package/docs/en/configure/app/output/enable-inline-styles.mdx +0 -22
- package/docs/en/configure/app/output/enable-latest-decorators.mdx +0 -14
- package/docs/en/configure/app/performance/transform-lodash.mdx +0 -52
- package/docs/en/configure/app/runtime/master-app.mdx +0 -36
- package/docs/en/configure/app/runtime/state.mdx +0 -52
- package/docs/en/configure/app/source/disable-entry-dirs.mdx +0 -38
- package/docs/en/configure/app/source/enable-custom-entry.mdx +0 -68
- package/docs/en/configure/app/source/module-scopes.mdx +0 -72
- package/docs/en/configure/app/source/resolve-extension-prefix.mdx +0 -55
- package/docs/en/configure/app/source/resolve-main-fields.mdx +0 -46
- package/docs/en/configure/app/tools/esbuild.mdx +0 -44
- package/docs/en/configure/app/tools/pug.mdx +0 -54
- package/docs/en/configure/app/tools/styled-components.mdx +0 -55
- package/docs/en/configure/app/tools/tailwindcss.mdx +0 -98
- package/docs/en/configure/app/tools/terser.mdx +0 -58
- package/docs/en/configure/app/tools/ts-loader.mdx +0 -76
- package/docs/en/configure/app/tools/webpack-chain.mdx +0 -249
- package/docs/en/configure/app/tools/webpack.mdx +0 -305
- package/docs/en/guides/deprecated.md +0 -17
- package/docs/en/guides/topic-detail/micro-frontend/c01-introduction.mdx +0 -27
- package/docs/en/guides/topic-detail/micro-frontend/c02-development.mdx +0 -290
- package/docs/en/guides/topic-detail/micro-frontend/c03-main-app.mdx +0 -298
- package/docs/en/guides/topic-detail/micro-frontend/c04-communicate.mdx +0 -58
- package/docs/en/guides/topic-detail/micro-frontend/c05-mixed-stack.mdx +0 -26
- package/docs/en/guides/topic-detail/model/_meta.json +0 -14
- package/docs/en/guides/topic-detail/model/auto-actions.mdx +0 -85
- package/docs/en/guides/topic-detail/model/computed-state.mdx +0 -148
- package/docs/en/guides/topic-detail/model/define-model.mdx +0 -62
- package/docs/en/guides/topic-detail/model/faq.mdx +0 -35
- package/docs/en/guides/topic-detail/model/manage-effects.mdx +0 -247
- package/docs/en/guides/topic-detail/model/model-communicate.mdx +0 -217
- package/docs/en/guides/topic-detail/model/performance.mdx +0 -167
- package/docs/en/guides/topic-detail/model/quick-start.mdx +0 -117
- package/docs/en/guides/topic-detail/model/redux-integration.mdx +0 -20
- package/docs/en/guides/topic-detail/model/typescript-best-practice.mdx +0 -68
- package/docs/en/guides/topic-detail/model/use-model.mdx +0 -243
- package/docs/en/guides/topic-detail/model/use-out-of-modernjs.mdx +0 -46
- package/docs/en/plugin/official/cli-plugins/plugin-swc.mdx +0 -363
- package/docs/en/plugin/official/cli-plugins/plugin-tailwind.mdx +0 -5
- package/docs/en/plugin/official/rsbuild-plugins/_meta.json +0 -1
- package/docs/en/plugin/official/rsbuild-plugins/plugin-esbuild.mdx +0 -205
- package/docs/en/plugin/official/rsbuild-plugins.mdx +0 -3
- package/docs/en/tutorials/first-app/c01-start.mdx +0 -99
- package/docs/en/tutorials/first-app/c02-component.mdx +0 -60
- package/docs/en/tutorials/first-app/c03-css.mdx +0 -324
- package/docs/en/tutorials/first-app/c04-routes.mdx +0 -172
- package/docs/en/tutorials/first-app/c05-loader.mdx +0 -87
- package/docs/en/tutorials/first-app/c06-model.mdx +0 -278
- package/docs/en/tutorials/first-app/c07-container.mdx +0 -281
- package/docs/en/tutorials/first-app/c08-entries.mdx +0 -135
- package/docs/zh/apis/app/hooks/server/index_.mdx +0 -10
- package/docs/zh/apis/app/hooks/src/index_.mdx +0 -39
- package/docs/zh/apis/app/hooks/src/stories.mdx +0 -16
- package/docs/zh/apis/app/runtime/app/define-config.mdx +0 -67
- package/docs/zh/apis/app/runtime/core/bootstrap.mdx +0 -74
- package/docs/zh/apis/app/runtime/core/create-app.mdx +0 -35
- package/docs/zh/apis/app/runtime/core/use-loader.mdx +0 -89
- package/docs/zh/apis/app/runtime/core/use-module-apps.mdx +0 -179
- package/docs/zh/apis/app/runtime/core/use-runtime-context.mdx +0 -116
- package/docs/zh/apis/app/runtime/model/Provider.mdx +0 -36
- package/docs/zh/apis/app/runtime/model/auto-actions.mdx +0 -122
- package/docs/zh/apis/app/runtime/model/connect.mdx +0 -143
- package/docs/zh/apis/app/runtime/model/create-app.mdx +0 -75
- package/docs/zh/apis/app/runtime/model/create-store.mdx +0 -61
- package/docs/zh/apis/app/runtime/model/handle-effect.mdx +0 -108
- package/docs/zh/apis/app/runtime/model/model_.mdx +0 -201
- package/docs/zh/apis/app/runtime/model/use-local-model.mdx +0 -29
- package/docs/zh/apis/app/runtime/model/use-model.mdx +0 -89
- package/docs/zh/apis/app/runtime/model/use-static-model.mdx +0 -49
- package/docs/zh/apis/app/runtime/model/use-store.mdx +0 -26
- package/docs/zh/apis/app/runtime/ssr/pre-render.mdx +0 -96
- package/docs/zh/apis/app/runtime/web-server/hook.mdx +0 -136
- package/docs/zh/apis/app/runtime/web-server/middleware.mdx +0 -114
- package/docs/zh/apis/app/runtime/web-server/unstable_middleware.mdx +0 -165
- package/docs/zh/components/bff-proxy-path-rewrite.mdx +0 -16
- package/docs/zh/components/bff-proxy-principle.mdx +0 -1
- package/docs/zh/components/builder.mdx +0 -3
- package/docs/zh/components/create-bff-api-app.mdx +0 -25
- package/docs/zh/components/custom-router-micro-frontend.mdx +0 -40
- package/docs/zh/components/enable-micro-frontend.mdx +0 -30
- package/docs/zh/components/enableSwc.mdx +0 -17
- package/docs/zh/components/global-proxy-config.mdx +0 -85
- package/docs/zh/components/global-proxy.mdx +0 -29
- package/docs/zh/components/package-manager.mdx +0 -11
- package/docs/zh/components/reduck-notify.mdx +0 -27
- package/docs/zh/components/reduck-tip.mdx +0 -8
- package/docs/zh/configure/app/auto-load-plugin.mdx +0 -66
- package/docs/zh/configure/app/deploy/microFrontend.mdx +0 -55
- package/docs/zh/configure/app/dev/port.mdx +0 -25
- package/docs/zh/configure/app/dev/proxy.mdx +0 -9
- package/docs/zh/configure/app/experiments/lazy-compilation.mdx +0 -105
- package/docs/zh/configure/app/html/disable-html-folder.mdx +0 -45
- package/docs/zh/configure/app/html/favicon-by-entries.mdx +0 -37
- package/docs/zh/configure/app/html/inject-by-entries.mdx +0 -37
- package/docs/zh/configure/app/html/meta-by-entries.mdx +0 -48
- package/docs/zh/configure/app/html/tags-by-entries.mdx +0 -44
- package/docs/zh/configure/app/html/template-by-entries.mdx +0 -33
- package/docs/zh/configure/app/html/template-parameters-by-entries.mdx +0 -36
- package/docs/zh/configure/app/html/title-by-entries.mdx +0 -37
- package/docs/zh/configure/app/output/css-module-local-ident-name.mdx +0 -21
- package/docs/zh/configure/app/output/disable-css-extract.mdx +0 -16
- package/docs/zh/configure/app/output/disable-filename-hash.mdx +0 -16
- package/docs/zh/configure/app/output/disable-minimize.mdx +0 -14
- package/docs/zh/configure/app/output/disable-node-polyfill.mdx +0 -22
- package/docs/zh/configure/app/output/disable-source-map.mdx +0 -31
- package/docs/zh/configure/app/output/enable-asset-fallback.mdx +0 -36
- package/docs/zh/configure/app/output/enable-inline-scripts.mdx +0 -22
- package/docs/zh/configure/app/output/enable-inline-styles.mdx +0 -22
- package/docs/zh/configure/app/output/enable-latest-decorators.mdx +0 -14
- package/docs/zh/configure/app/performance/transform-lodash.mdx +0 -52
- package/docs/zh/configure/app/runtime/master-app.mdx +0 -38
- package/docs/zh/configure/app/runtime/state.mdx +0 -52
- package/docs/zh/configure/app/source/disable-entry-dirs.mdx +0 -38
- package/docs/zh/configure/app/source/enable-custom-entry.mdx +0 -67
- package/docs/zh/configure/app/source/module-scopes.mdx +0 -72
- package/docs/zh/configure/app/source/resolve-extension-prefix.mdx +0 -57
- package/docs/zh/configure/app/source/resolve-main-fields.mdx +0 -46
- package/docs/zh/configure/app/tools/esbuild.mdx +0 -44
- package/docs/zh/configure/app/tools/pug.mdx +0 -54
- package/docs/zh/configure/app/tools/styled-components.mdx +0 -54
- package/docs/zh/configure/app/tools/tailwindcss.mdx +0 -98
- package/docs/zh/configure/app/tools/terser.mdx +0 -58
- package/docs/zh/configure/app/tools/ts-loader.mdx +0 -76
- package/docs/zh/configure/app/tools/webpack-chain.mdx +0 -253
- package/docs/zh/configure/app/tools/webpack.mdx +0 -305
- package/docs/zh/guides/advanced-features/rspack-start.mdx +0 -154
- package/docs/zh/guides/deprecated.md +0 -19
- package/docs/zh/guides/topic-detail/micro-frontend/c01-introduction.mdx +0 -26
- package/docs/zh/guides/topic-detail/micro-frontend/c02-development.mdx +0 -332
- package/docs/zh/guides/topic-detail/micro-frontend/c03-main-app.mdx +0 -296
- package/docs/zh/guides/topic-detail/micro-frontend/c04-communicate.mdx +0 -58
- package/docs/zh/guides/topic-detail/micro-frontend/c05-mixed-stack.mdx +0 -27
- package/docs/zh/guides/topic-detail/model/_meta.json +0 -14
- package/docs/zh/guides/topic-detail/model/auto-actions.mdx +0 -88
- package/docs/zh/guides/topic-detail/model/computed-state.mdx +0 -147
- package/docs/zh/guides/topic-detail/model/define-model.mdx +0 -63
- package/docs/zh/guides/topic-detail/model/faq.mdx +0 -36
- package/docs/zh/guides/topic-detail/model/manage-effects.mdx +0 -256
- package/docs/zh/guides/topic-detail/model/model-communicate.mdx +0 -217
- package/docs/zh/guides/topic-detail/model/performance.mdx +0 -167
- package/docs/zh/guides/topic-detail/model/quick-start.mdx +0 -117
- package/docs/zh/guides/topic-detail/model/redux-integration.mdx +0 -20
- package/docs/zh/guides/topic-detail/model/typescript-best-practice.mdx +0 -67
- package/docs/zh/guides/topic-detail/model/use-model.mdx +0 -248
- package/docs/zh/guides/topic-detail/model/use-out-of-modernjs.mdx +0 -46
- package/docs/zh/plugin/official/cli-plugins/plugin-swc.mdx +0 -351
- package/docs/zh/plugin/official/cli-plugins/plugin-tailwind.mdx +0 -5
- package/docs/zh/plugin/official/rsbuild-plugins/_meta.json +0 -1
- package/docs/zh/plugin/official/rsbuild-plugins/plugin-esbuild.mdx +0 -201
- package/docs/zh/plugin/official/rsbuild-plugins.mdx +0 -3
- package/docs/zh/tutorials/first-app/c01-start.mdx +0 -99
- package/docs/zh/tutorials/first-app/c02-component.mdx +0 -60
- package/docs/zh/tutorials/first-app/c03-css.mdx +0 -323
- package/docs/zh/tutorials/first-app/c04-routes.mdx +0 -172
- package/docs/zh/tutorials/first-app/c05-loader.mdx +0 -89
- package/docs/zh/tutorials/first-app/c06-model.mdx +0 -274
- package/docs/zh/tutorials/first-app/c07-container.mdx +0 -281
- package/docs/zh/tutorials/first-app/c08-entries.mdx +0 -135
- /package/docs/en/components/{reduck-migration.mdx → auto-upgrade.mdx} +0 -0
- /package/docs/{zh/components/reduck-migration.mdx → en/components/international/platform-support.mdx} +0 -0
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
# 自动生成 Actions
|
|
2
|
-
|
|
3
|
-
在 [快速上手](/guides/topic-detail/model/quick-start) 中,我们实现最简单的计数器 Model 也需要 10 行代码。
|
|
4
|
-
实际上,Modern.js 支持根据声明的 `state` 类型,自动生成常用的 Actions,从而简化模板代码量。当前支持的类型有:
|
|
5
|
-
|
|
6
|
-
- 原始数据类型
|
|
7
|
-
- 数组类型
|
|
8
|
-
- 简单对象类型(Plain Object)
|
|
9
|
-
|
|
10
|
-
## 原始数据类型
|
|
11
|
-
|
|
12
|
-
```ts
|
|
13
|
-
const countModel = model('count').define({ state: 1 });
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
如上我们仅用一行就完成了一个简单的 `countModel`。使用 Model 的示例代码如下:
|
|
17
|
-
|
|
18
|
-
```tsx
|
|
19
|
-
function Counter() {
|
|
20
|
-
const [state, actions] = useModel(countModel);
|
|
21
|
-
|
|
22
|
-
useEffect(() => {
|
|
23
|
-
// 增加 1
|
|
24
|
-
actions.setState(state + 1);
|
|
25
|
-
}, []);
|
|
26
|
-
}
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
## 数组类型
|
|
30
|
-
|
|
31
|
-
当 State 为数组类型时,自动生成 Actions 的示例代码如下:
|
|
32
|
-
|
|
33
|
-
```ts
|
|
34
|
-
const countModel = model('count').define({ state: [] });
|
|
35
|
-
|
|
36
|
-
function Counter() {
|
|
37
|
-
const [state, actions] = useModel(countModel);
|
|
38
|
-
|
|
39
|
-
useEffect(() => {
|
|
40
|
-
actions.push(1);
|
|
41
|
-
actions.pop();
|
|
42
|
-
actions.shift();
|
|
43
|
-
actions.unshift(1);
|
|
44
|
-
actions.concat([1]);
|
|
45
|
-
actions.splice(0, 1, 2);
|
|
46
|
-
actions.filter(value => value > 1);
|
|
47
|
-
}, []);
|
|
48
|
-
}
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
我们可以使用 JavaScript Array 对象的方法,修改 State。
|
|
52
|
-
|
|
53
|
-
## 简单对象类型
|
|
54
|
-
|
|
55
|
-
当 State 为简单对象类型时,自动生成 Actions 的示例代码如下:
|
|
56
|
-
|
|
57
|
-
```ts
|
|
58
|
-
const countModel = model('count').define({
|
|
59
|
-
state: {
|
|
60
|
-
a: 1,
|
|
61
|
-
b: [],
|
|
62
|
-
c: {},
|
|
63
|
-
},
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
function Counter() {
|
|
67
|
-
const [state, actions] = useModel(countModel);
|
|
68
|
-
|
|
69
|
-
useEffect(() => {
|
|
70
|
-
actions.setA(2);
|
|
71
|
-
actions.setB([1]);
|
|
72
|
-
actions.setC({ a: 1 });
|
|
73
|
-
}, []);
|
|
74
|
-
}
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
根据 `a`、`b`、`c` 三个不同的字段分别生成 `setA`、`setB`、`setC` 三个 Actions。
|
|
78
|
-
|
|
79
|
-
:::info
|
|
80
|
-
当用户自定义的 Action 和 Modern.js 自动生成的 Action 名字一致时,用户自定义的 Action 优先级更高。例如,
|
|
81
|
-
在 `countModel` 中已经自定义 `setA` 这个 Action,调用 `actions.setA()` 时,最终执行的是用户自定义的 `setA`。
|
|
82
|
-
|
|
83
|
-
:::
|
|
84
|
-
|
|
85
|
-
:::info 补充信息
|
|
86
|
-
相关 API 的更多介绍,请参考[这里](/apis/app/runtime/model/auto-actions)。
|
|
87
|
-
|
|
88
|
-
:::
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
# 衍生状态
|
|
2
|
-
|
|
3
|
-
一些场景中,组件需要对 Model 中的 State 进行进一步计算,才能在组件中使用,这部分逻辑可以直接写在组件内部,也可以通过 Model 的衍生状态实现。
|
|
4
|
-
衍生状态定义在 Model 中的 `computed` 字段下。根据依赖的 Model 的不同、返回类型的不同,衍生状态的定义方法可以分为以下 3 种。
|
|
5
|
-
|
|
6
|
-
## 只依赖自身的 State
|
|
7
|
-
|
|
8
|
-
衍生状态只依赖当前 Model 的 State,State 会作为第一个参数,传入衍生状态的定义函数中。
|
|
9
|
-
|
|
10
|
-
例如, todo 应用的 State 有 `items` 和 `filter`,`filter` 用于过滤当前页面显示的 todo 项,所以我们定义了一个 `visibleTodos` 的衍生状态可以直接在组件中使用。示例代码如下:
|
|
11
|
-
|
|
12
|
-
```ts
|
|
13
|
-
/**
|
|
14
|
-
* 假设 todo item 结构如下:
|
|
15
|
-
{
|
|
16
|
-
id: string; // id
|
|
17
|
-
text: string; // todo 事项
|
|
18
|
-
completed: boolean; // 完成状态:0 代表未完成,1 代表完成
|
|
19
|
-
}
|
|
20
|
-
**/
|
|
21
|
-
|
|
22
|
-
const todoModel = model('todo').define({
|
|
23
|
-
state: {
|
|
24
|
-
items: [],
|
|
25
|
-
filter: 'ALL', // ALL: 显示全部;COMPLETED:显示完成的事项;ACTIVE:显示未完成的事项
|
|
26
|
-
},
|
|
27
|
-
computed: {
|
|
28
|
-
visibleTodos: state => {
|
|
29
|
-
switch (state.filter) {
|
|
30
|
-
case 'ALL':
|
|
31
|
-
return state.items;
|
|
32
|
-
case 'COMPLETED':
|
|
33
|
-
return todos.filter(t => t.completed);
|
|
34
|
-
case 'ACTIVE':
|
|
35
|
-
return todos.filter(t => !t.completed);
|
|
36
|
-
default:
|
|
37
|
-
return [];
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
|
-
});
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
衍生状态最终会和 Model 的 State 进行合并,因此,可以通过 Model 的 State 对象访问到衍生状态,例如,`visibleTodos` 在组件内的使用方式如下:
|
|
45
|
-
|
|
46
|
-
```ts
|
|
47
|
-
function Todo() {
|
|
48
|
-
const [state, actions] = useModel(todoModel);
|
|
49
|
-
|
|
50
|
-
return (
|
|
51
|
-
<div>
|
|
52
|
-
<div>
|
|
53
|
-
{state.visibleTodos.map(item => (
|
|
54
|
-
<div key={item.id}>{item.text}</div>
|
|
55
|
-
))}
|
|
56
|
-
</div>
|
|
57
|
-
</div>
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
## 依赖其他 Model 的 State
|
|
63
|
-
|
|
64
|
-
除了依赖当前 Model 的 State,衍生状态还依赖其他 Model 的 State,这时候衍生状态的定义格式为:
|
|
65
|
-
|
|
66
|
-
```ts
|
|
67
|
-
[stateKey]: [...depModels, (selfState, ...depModels) => computedState]
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
下面的示例,演示了 `barModel` 的衍生状态 `combinedValue` 是如何依赖 `fooModel` 的 State 的。
|
|
71
|
-
|
|
72
|
-
```ts
|
|
73
|
-
const fooModel = model('foo').define({
|
|
74
|
-
state: {
|
|
75
|
-
value: 'foo',
|
|
76
|
-
},
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
const barModel = model('bar').define({
|
|
80
|
-
state: {
|
|
81
|
-
value: 'foo',
|
|
82
|
-
},
|
|
83
|
-
computed: {
|
|
84
|
-
combinedValue: [
|
|
85
|
-
fooModel,
|
|
86
|
-
(state, fooState) => state.value + fooState.value,
|
|
87
|
-
],
|
|
88
|
-
},
|
|
89
|
-
});
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
## 函数类型的衍生状态
|
|
93
|
-
|
|
94
|
-
衍生状态还可以返回一个函数。这时候衍生状态的定义格式为:
|
|
95
|
-
|
|
96
|
-
```ts
|
|
97
|
-
[stateKey]: (state) => (...args) => computedState // 只依赖自身的 state
|
|
98
|
-
[stateKey]: [...depModels, (selfState, ...depModels) => (...args) => computedState] // 依赖其他 Model 的 state
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
假设,todo 应用的 state 不存储 `filter` 状态,而是直接在组件中使用,那么 `visibleTodos` 可以是一个函数类型的值,这个函数在组件中使用的时候,接收 `filter` 参数。如下所示:
|
|
102
|
-
|
|
103
|
-
```ts
|
|
104
|
-
const todoModel = model('todo').define({
|
|
105
|
-
state: {
|
|
106
|
-
items: [],
|
|
107
|
-
},
|
|
108
|
-
computed: {
|
|
109
|
-
visibleTodos: state => filter => {
|
|
110
|
-
switch (filter) {
|
|
111
|
-
case 'ALL':
|
|
112
|
-
return state.items;
|
|
113
|
-
case 'COMPLETED':
|
|
114
|
-
return todos.filter(t => t.completed);
|
|
115
|
-
case 'ACTIVE':
|
|
116
|
-
return todos.filter(t => !t.completed);
|
|
117
|
-
default:
|
|
118
|
-
return [];
|
|
119
|
-
}
|
|
120
|
-
},
|
|
121
|
-
},
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
function Todo(props) {
|
|
125
|
-
// filter 状态通过 props 传入
|
|
126
|
-
const { filter } = props;
|
|
127
|
-
const [state, actions] = useModel(todoModel);
|
|
128
|
-
|
|
129
|
-
// 计算得到最终要显示的 todos
|
|
130
|
-
const todos = state.visibleTodos(filter);
|
|
131
|
-
|
|
132
|
-
return (
|
|
133
|
-
<div>
|
|
134
|
-
<div>
|
|
135
|
-
{todos.map(item => (
|
|
136
|
-
<div key={item.id}>{item.text}</div>
|
|
137
|
-
))}
|
|
138
|
-
</div>
|
|
139
|
-
</div>
|
|
140
|
-
);
|
|
141
|
-
}
|
|
142
|
-
```
|
|
143
|
-
|
|
144
|
-
:::info 更多参考
|
|
145
|
-
[使用 Model](/guides/topic-detail/model/computed-state)
|
|
146
|
-
|
|
147
|
-
:::
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
# 创建 Model
|
|
2
|
-
|
|
3
|
-
上一节的计数器应用中,我们简单演示了如何创建一个 Model。本节我们将详细介绍 Model 的创建方法。
|
|
4
|
-
|
|
5
|
-
通过 `model` API 创建 Model,例如,`model('foo')` 表示要创建一个名为 `foo` 的 Model,通过调用 `model('foo')` 返回的 `define` 函数,定义 Model 包含的 State、Actions 等:
|
|
6
|
-
|
|
7
|
-
```js
|
|
8
|
-
import { model, useModel } from '@modern-js/runtime/model';
|
|
9
|
-
|
|
10
|
-
const fooModel = model('foo').define({
|
|
11
|
-
state: {
|
|
12
|
-
value: 'foo',
|
|
13
|
-
},
|
|
14
|
-
actions: {
|
|
15
|
-
setValue: (state, payload){
|
|
16
|
-
state.value = payload
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
:::info
|
|
23
|
-
|
|
24
|
-
- Model 中的 Action 中不能包含有副作用的逻辑,如请求 HTTP 接口,访问 localStorage 等。
|
|
25
|
-
- `setValue` 内部直接修改了入参 State,看起来是违反了纯函数的定义,实际上 Reduck 内部使用 [immer](https://github.com/immerjs/immer) 来修改不可变对象,保证了这种写法不会影响对象的不可变性,所以 `setValue` 仍然是一个纯函数。当然,你也可以直接在 Action 中返回一个新对象,不过这样的写法会更加复杂一些。
|
|
26
|
-
|
|
27
|
-
:::
|
|
28
|
-
|
|
29
|
-
`define` 接收的参数,只是对 Model 原始结构的描述:内部定义的 State、Actions 等。`define` 返回值 `fooModel` 才是真正创建得到的 Model 对象。例如,虽然 `setValue`,有 2 个参数,但是当真正调用 `setValue` 这个 Action 时,我们只需要传入 `payload` 一个参数,因为我们调用的是 `fooModel` 上的 Action 方法,而不是 Model 原始结构上描述的 Action 方法。详细参考[使用 Model](/guides/topic-detail/model/use-model)。
|
|
30
|
-
|
|
31
|
-
`define` 除了接收对象类型的参数,还可以接收函数类型的参数。例如:
|
|
32
|
-
|
|
33
|
-
```js
|
|
34
|
-
import { model, useModel } from '@modern-js/runtime/model';
|
|
35
|
-
|
|
36
|
-
const fooModel = model('foo').define((context, utils) => {
|
|
37
|
-
return {
|
|
38
|
-
state: {
|
|
39
|
-
value: 'foo',
|
|
40
|
-
},
|
|
41
|
-
actions: {
|
|
42
|
-
setValue: (state, payload){
|
|
43
|
-
state.value = payload
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
通过函数定义 Model 时,函数内部会自动传入 `context`、`utils` 2 个参数,`context` 是 Reduck 的上下文对象,可以获取到 `store` 对象,`utils` 提供了一组工具函数,方便实现 Model 通信等复杂功能需求。
|
|
51
|
-
|
|
52
|
-
Model 支持复制。例如:
|
|
53
|
-
|
|
54
|
-
```ts
|
|
55
|
-
const barModel = fooModel('bar');
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
barModel 是基于 fooModel 创建出一个的新的 Model 对象,类比面向对象编程语言中的概念,barModel 和 fooModel 是基于同一个类(Class)创建出的 2 个实例对象。当两个模块的状态管理逻辑相同,例如一个页面中的两个 tab 模块,使用的数据的结构和逻辑相同,区别只是从不同的接口获取数据,那么可以通过 Model 复制的方式,创建 2 个不同的 Model 对象。
|
|
59
|
-
|
|
60
|
-
:::info 补充信息
|
|
61
|
-
本节涉及的 API 的详细定义,请参考[这里](/apis/app/runtime/model/model_)。
|
|
62
|
-
|
|
63
|
-
:::
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
# 常见问题
|
|
2
|
-
|
|
3
|
-
## 浏览器兼容性
|
|
4
|
-
|
|
5
|
-
Reduck 的编译构建产物默认使用 ES6 语法,如果你需要支持更低版本的浏览器,请将 `@modern-js-reduck` 命名空间下的所有包加入到应用的编译过程。
|
|
6
|
-
|
|
7
|
-
:::info 补充信息
|
|
8
|
-
Reduck 使用的 [`@babel/preset-env`](https://babeljs.io/docs/en/babel-preset-env) 的详细[配置](https://github.com/web-infra-dev/reduck/blob/main/common/config.js#L10~L17)。
|
|
9
|
-
|
|
10
|
-
:::
|
|
11
|
-
|
|
12
|
-
## 微前端子应用 Model 访问主应用 Model
|
|
13
|
-
|
|
14
|
-
微前端子应用 Model 访问主应用 Model 时,如果该 **Model** 在主应用尚未挂载,会自动挂载到子应用上。
|
|
15
|
-
|
|
16
|
-
示例:
|
|
17
|
-
|
|
18
|
-
```ts
|
|
19
|
-
import { useModel } from '@modern-js/runtime/model';
|
|
20
|
-
import parentModel from '@MasterApp/models/todoModel';
|
|
21
|
-
|
|
22
|
-
function SubModelApp() {
|
|
23
|
-
const [state, actions] = useModel(parentModel);
|
|
24
|
-
|
|
25
|
-
return <div>...</div>;
|
|
26
|
-
}
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-

|
|
30
|
-
|
|
31
|
-
为了避免意外降级挂载,建议将主应用所需要共享的 Model 预先挂载:
|
|
32
|
-
|
|
33
|
-
```ts
|
|
34
|
-
// App 是主应用的入口组件,sharedModel1、sharedModel2 是需要共享的 Model。
|
|
35
|
-
App.models = [sharedModel1, sharedModel2];
|
|
36
|
-
```
|
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
# 副作用管理
|
|
2
|
-
|
|
3
|
-
Model 中的 Action 必须是一个纯函数,执行过程中不会产生任何副作用。但在真实的业务中,我们会遇到很多副作用场景,如:请求 HTTP 接口获取状态数据,或者在更新状态的同时修改 localStorage、发送事件等。在 Reduck 中,是通过 Model 的 Effects 函数管理副作用的。
|
|
4
|
-
|
|
5
|
-
## 副作用对 State 修改
|
|
6
|
-
|
|
7
|
-
副作用修改 State,最常见的场景就是请求 HTTP 接口,更新状态数据。
|
|
8
|
-
|
|
9
|
-
我们以一个简单的 `todoModel` 为例。其有一个 `load` 的副作用函数,请求远端的 TODO 列表,请求成功之后更新 `state.items` 字段。
|
|
10
|
-
|
|
11
|
-
```ts
|
|
12
|
-
const todoModel = model('todo').define({
|
|
13
|
-
state: {
|
|
14
|
-
items: [],
|
|
15
|
-
loading: false,
|
|
16
|
-
error: null,
|
|
17
|
-
},
|
|
18
|
-
actions: {
|
|
19
|
-
load: {
|
|
20
|
-
pending(state) {
|
|
21
|
-
state.loading = true;
|
|
22
|
-
},
|
|
23
|
-
fulfilled(state, items) {
|
|
24
|
-
state.items = items;
|
|
25
|
-
state.loading = false;
|
|
26
|
-
},
|
|
27
|
-
rejected(state, error) {
|
|
28
|
-
state.error = error;
|
|
29
|
-
state.loading = false;
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
effects: {
|
|
34
|
-
// Promise 副作用
|
|
35
|
-
async load() {
|
|
36
|
-
return new Promise(resolve => {
|
|
37
|
-
setTimeout(() => resolve(['Learn Modern.js']), 2000);
|
|
38
|
-
});
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
|
-
});
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
副作用函数统一定义在 `effects` 字段下。这里我们写了一个 `load` 函数,它返回一个 Promise,Promise 执行成功后,返回 TODO 列表 `["Lerna Modern.js"]`。
|
|
45
|
-
|
|
46
|
-
副作用函数需要和 actions 配合使用,才能完成状态的修改。因此,我们在 `actions` 中定义了一个 `load`(命名需要和 `effects` 下的副作用函数的名字保持一致)对象,包含 `pending`、`fulfilled`、`rejected` 3 个 action,分别是对副作用函数 `load` 返回的 `Promise` 的三种状态( pending、fulfilled、rejected )的处理:
|
|
47
|
-
|
|
48
|
-
- `pending`:接收当前状态 `state` 作为参数,新的状态中 `loading` 设为 `true`。
|
|
49
|
-
- `fulfilled`:接收当前状态 `state` 和 Promise fulfilled 状态的值 `items` 为参数,新的状态中 `items` 等于参数 `items`、`loading` 设为 `false`。
|
|
50
|
-
- `rejected`:接收当前状态 `state` 和 Promise rejected 状态的错误 `error` 为参数,新的状态中 `error` 等于参数 `error`、`loading` 设为 `false`。
|
|
51
|
-
|
|
52
|
-
组件中如何调用 effects 函数呢? effects 函数会被合并到 actions 对象上,因此可以通过 actions 对象调用 effects 函数,如下所示:
|
|
53
|
-
|
|
54
|
-
```ts
|
|
55
|
-
function Todo() {
|
|
56
|
-
const [state, actions] = useModel(todoModel);
|
|
57
|
-
|
|
58
|
-
useEffect(() => {
|
|
59
|
-
// 调用 effects 函数
|
|
60
|
-
actions.load();
|
|
61
|
-
}, []);
|
|
62
|
-
|
|
63
|
-
if (state.loading) {
|
|
64
|
-
return <div>loading....</div>;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return (
|
|
68
|
-
<div>
|
|
69
|
-
<div>
|
|
70
|
-
{state.items.map((item, index) => (
|
|
71
|
-
<div key={index}>{item}</div>
|
|
72
|
-
))}
|
|
73
|
-
</div>
|
|
74
|
-
</div>
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
上面的示例中, `pending`、`fulfilled`、`rejected` 3 个 action,对于用于获取数据的 HTTP 请求场景下,一般都是需要的。Reduck 提供了一个工具函数 `handleEffect`,用于简化这种场景下的 action 创建。
|
|
80
|
-
|
|
81
|
-
`handleEffect` 约定这种副作用场景下, Model 的 State 结构包含 `result`、`error`、`pending` 3 个字段,初始值为:
|
|
82
|
-
|
|
83
|
-
```ts
|
|
84
|
-
{
|
|
85
|
-
result: null,
|
|
86
|
-
error: null,
|
|
87
|
-
pending: false,
|
|
88
|
-
}
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
调用 `handleEffect` 会返回如下数据结构:
|
|
92
|
-
|
|
93
|
-
```ts
|
|
94
|
-
{
|
|
95
|
-
pending() { // ... },
|
|
96
|
-
fulfilled() { // ... },
|
|
97
|
-
rejected() { // ... }
|
|
98
|
-
}
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
这个数据结构和我们在 `actions` 下的 `load` 对象的数据结构是相同的。`handleEffect` 返回的对象,其实就是对应了 Effects 函数需要的 3 个 action。
|
|
102
|
-
|
|
103
|
-
利用 `handleEffect`,改写 `todoModel`:
|
|
104
|
-
|
|
105
|
-
```ts
|
|
106
|
-
const todoModel = model('todo').define({
|
|
107
|
-
state: {
|
|
108
|
-
items: [],
|
|
109
|
-
loading: false,
|
|
110
|
-
error: null,
|
|
111
|
-
},
|
|
112
|
-
actions: {
|
|
113
|
-
load: handleEffect({ result: 'items' }),
|
|
114
|
-
},
|
|
115
|
-
effects: {
|
|
116
|
-
// Promise 副作用
|
|
117
|
-
async load() {
|
|
118
|
-
return new Promise(resolve => {
|
|
119
|
-
setTimeout(() => resolve(['Learn Modern.js']), 2000);
|
|
120
|
-
});
|
|
121
|
-
},
|
|
122
|
-
},
|
|
123
|
-
});
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
`handleEffect` 接收的参数对象,将 `result` 设置为 `item`。因为 `todoModel` 的 state,使用 `items` 作为 key 保存 todo 列表数据,而不是使用 `handleEffect` 默认的 `result` 作为 key,所以这里需要进行配置。
|
|
127
|
-
|
|
128
|
-
明显可见,通过 `handleEffect` 实现的 `todoModel` 比之前的实现有了很大精简。
|
|
129
|
-
|
|
130
|
-
如果不希望 pending、fulfilled、rejected 3 种状态都被 `handleEffect` 自动处理,例如 fulfilled 需要手动处理较复杂的数据类型,但是 pending、rejected 依旧想进行自动化处理,可以参考如下写法:
|
|
131
|
-
|
|
132
|
-
```ts
|
|
133
|
-
actions: {
|
|
134
|
-
load: {
|
|
135
|
-
...handleEffect(),
|
|
136
|
-
fulfilled(state, payload) {
|
|
137
|
-
// 手动处理
|
|
138
|
-
},
|
|
139
|
-
},
|
|
140
|
-
},
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
:::info 补充信息
|
|
144
|
-
`handleEffect` [API](/apis/app/runtime/model/handle-effect)。
|
|
145
|
-
|
|
146
|
-
:::
|
|
147
|
-
|
|
148
|
-
Effects 函数中,也支持手动调用 Actions,例如:
|
|
149
|
-
|
|
150
|
-
```ts
|
|
151
|
-
const todoModel = model('todo').define((context, utils) => ({
|
|
152
|
-
state: {
|
|
153
|
-
items: [],
|
|
154
|
-
loading: false,
|
|
155
|
-
error: null,
|
|
156
|
-
},
|
|
157
|
-
actions: {
|
|
158
|
-
pending(state) {
|
|
159
|
-
state.loading = true;
|
|
160
|
-
},
|
|
161
|
-
fulfilled(state, items) {
|
|
162
|
-
state.items = items;
|
|
163
|
-
state.loading = false;
|
|
164
|
-
},
|
|
165
|
-
},
|
|
166
|
-
effects: {
|
|
167
|
-
async load() {
|
|
168
|
-
// 通过 utils.use 获取当前 Model 对象的 actions
|
|
169
|
-
const [, actions] = utils.use(todoModel);
|
|
170
|
-
// 手动调用 action
|
|
171
|
-
actions.pending();
|
|
172
|
-
|
|
173
|
-
return new Promise(resolve => {
|
|
174
|
-
setTimeout(() => {
|
|
175
|
-
const items = ['Learn Modern.js'];
|
|
176
|
-
// 手动调用 action
|
|
177
|
-
actions.fulfilled(items);
|
|
178
|
-
resolve(items);
|
|
179
|
-
}, 2000);
|
|
180
|
-
});
|
|
181
|
-
},
|
|
182
|
-
},
|
|
183
|
-
}));
|
|
184
|
-
```
|
|
185
|
-
|
|
186
|
-
:::info
|
|
187
|
-
可以使用 `use` 函数加载其它 Model(包括 Model 自身),实现 [Model 间通信](/guides/topic-detail/model/model-communicate)。
|
|
188
|
-
|
|
189
|
-
:::
|
|
190
|
-
|
|
191
|
-
## 副作用不影响 state
|
|
192
|
-
|
|
193
|
-
有些场景下,我们只需要读取 State,执行相关副作用逻辑,副作用不会修改 State。
|
|
194
|
-
|
|
195
|
-
例如,存储某些 State 到 `localStorage`:
|
|
196
|
-
|
|
197
|
-
```ts
|
|
198
|
-
const fooModel = model('foo').define((context, utils) => ({
|
|
199
|
-
state: {
|
|
200
|
-
value: 'foo',
|
|
201
|
-
},
|
|
202
|
-
effects: {
|
|
203
|
-
setLocalStorage(key) {
|
|
204
|
-
const [state] = utils.use(fooModel);
|
|
205
|
-
localStorage.set(key, state.value);
|
|
206
|
-
return 'success';
|
|
207
|
-
},
|
|
208
|
-
},
|
|
209
|
-
}));
|
|
210
|
-
```
|
|
211
|
-
|
|
212
|
-
或者是向服务端发送数据:
|
|
213
|
-
|
|
214
|
-
```ts
|
|
215
|
-
const fooModel = model('foo').define({
|
|
216
|
-
state: {
|
|
217
|
-
value: 'foo',
|
|
218
|
-
},
|
|
219
|
-
effects: {
|
|
220
|
-
async sendData(data) {
|
|
221
|
-
const res = await fetch('url', {
|
|
222
|
-
method: 'POST',
|
|
223
|
-
body: data,
|
|
224
|
-
});
|
|
225
|
-
return res.json();
|
|
226
|
-
},
|
|
227
|
-
},
|
|
228
|
-
});
|
|
229
|
-
```
|
|
230
|
-
|
|
231
|
-
## 副作用函数返回值
|
|
232
|
-
|
|
233
|
-
有时候,我们希望能根据副作用函数的执行结果,直接执行后续逻辑。这时候,就需要使用 Effects 函数的返回。
|
|
234
|
-
|
|
235
|
-
例如,当点击发送按钮,发送数据成功后,立即关闭当前的弹窗;如果失败,显示错误信息。我们可以通过如下代码实现:
|
|
236
|
-
|
|
237
|
-
```ts
|
|
238
|
-
// 代码仅做示意,不能执行
|
|
239
|
-
// 组件内部 发送按钮 的响应函数
|
|
240
|
-
const handleClick = async () => {
|
|
241
|
-
// sendData 返回代表状态的字符串
|
|
242
|
-
const result = await actions.sendData('some data');
|
|
243
|
-
if (result === 'success') {
|
|
244
|
-
// 关闭弹窗
|
|
245
|
-
closeModal();
|
|
246
|
-
} else {
|
|
247
|
-
// 显示错误
|
|
248
|
-
showError(result);
|
|
249
|
-
}
|
|
250
|
-
};
|
|
251
|
-
```
|
|
252
|
-
|
|
253
|
-
:::info 补充信息
|
|
254
|
-
[示例代码](https://github.com/web-infra-dev/modern-js-examples/tree/main/examples/runtime-api/effects)
|
|
255
|
-
|
|
256
|
-
:::
|