index
int64
0
0
repo_id
stringlengths
16
181
file_path
stringlengths
28
270
content
stringlengths
1
11.6M
__index_level_0__
int64
0
10k
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail/generator
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail/generator/new/_category_.json
{ "label": "new Command", "position": 2 }
7,400
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail/generator
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail/generator/new/config.md
--- sidebar_position: 3 --- # Configuration Parameters The `new` command provides the [--config](/guides/topic-detail/generator/new/option.html#-c,---config-<config>) parameter, which is used to specify the answers to interactive questions in advance during the execution process. Here, we will introduce the fields a...
7,401
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail/generator
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail/generator/new/option.md
--- sidebar_position: 2 --- # CLI Parameters The `new` command provides many configuration parameters to configure its behavior during execution, which can be viewed using the `--help` parameter: ```bash npm run new --help Usage: modern new [options] enable optional features or add a new entry Options: --lang <...
7,402
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail/generator
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail/generator/new/use.md
--- sidebar_position: 1 --- # Usage In Web App, Npm Module and Monorepo projects, we provide the `new` command to create project elements, enable features and create sub-project. ## Web App Web App projects use the `new` command provided by `@modern-js/app-tools`. The `new` command provides three types of operati...
7,403
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail/generator
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail/generator/plugin/_category_.json
{ "label": "Generator Plugin", "position": 2 }
7,404
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail/generator
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail/generator/plugin/category.md
--- sidebar_position: 2 --- ## Introduction There are two types of generator plugin: - Extension: Web App(Npm Module) = Web App(Npm Module) + Generator Plugin - Custom: New Application(Npm Module) = Web App(Npm Module) + Generator Plugin In simpler terms, extension means using the original project name of Modern....
7,405
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail/generator
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail/generator/plugin/context.md
--- sidebar_position: 4 --- # Context By default, generator plugins will export a function that takes `context` as a parameter. During execution, `context` will be automatically injected into the generator plugin. ```ts title="src/index.ts" import { IPluginContext, ForgedAPI } from '@modern-js/generator-plugin'; ex...
7,406
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail/generator
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail/generator/plugin/structure.md
--- sidebar_position: 1 --- # Introduction and Project Creation ## Introduction Modern.js provides engineering solutions such as Web App and Npm Module. By using the `@modern-js/create` tool, you can create initial project templates for engineering solutions. The initial project template provides a basic code develo...
7,407
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail/generator
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail/generator/plugin/use.md
--- sidebar_position: 3 --- # Usage `@modern-js/create` provides the `--plugin` parameter to run the generator plugin project. `--plugin` supports three formats: ## Absolute path Suitable for local development and debugging. After development is completed, build the project by running `npm run build` in the genera...
7,408
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail/generator/plugin
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail/generator/plugin/api/_category_.json
{ "label": "API", "position": 5 }
7,409
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail/generator/plugin
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail/generator/plugin/api/afterForged.md
--- sidebar_position: 3 --- # afterForged `afterForged` is a lifecycle function used for other step operations after file operations in generator plugin. ## Types ```ts export type AfterForgedAPI = { isInGitRepo: () => Promise<boolean>; initGitRepo: () => Promise<void>; gitAddAndCommit: (commitMessage: string...
7,410
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail/generator/plugin
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail/generator/plugin/api/context.md
--- sidebar_position: 1 --- # context The generator plugin exports a function by default in the `main` file, and the function parameter is `context`. All APIs provided by the generator plugin are provided by this `context`. ## Types Let's first understand the type definition of `context`: ```ts export interface IP...
7,411
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail/generator/plugin
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail/generator/plugin/api/input.md
--- sidebar_position: 4 --- # Input Generator plugin provides a way to interact with users through Input, which is defined using JSON Schema: For example: ```js const schema = { type: 'object', properties: { language: { type: 'string', title: 'Please select the programming language:', enum...
7,412
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail/generator/plugin
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail/generator/plugin/api/onForged.md
--- sidebar_position: 2 --- # onForged `onForged` is a lifecycle function used for file operations in generator plugin. ## Types ```ts export type ForgedAPI = { addFile: (params: AddFileParams) => Promise<void>; addManyFiles: (params: AddManyFilesParams) => Promise<void>; updateJSONFile: (fileName: string, up...
7,413
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail/micro-frontend/_category_.json
{ "label": "Micro Frontend", "position": 2 }
7,414
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail/micro-frontend/c01-introduction.mdx
--- sidebar_position: 1 title: Introduction --- # Introduction import MicroFrontend from '@modern-js/builder-doc/docs/en/shared/micro-frontend.md'; <MicroFrontend /> ## Keyword In the micro frontend, applications are divided into **main application**, and **sub-applications**. - Main application: The base project...
7,415
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail/micro-frontend/c02-development.mdx
--- sidebar_position: 2 title: Development --- # Experience Micro Frontend Through this chapter you can learn: - How to create the main application and sub-application of the micro frontend project. - Basic process of micro frontend project development. ## Create an app Currently supports two routing modes - Self...
7,416
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail/micro-frontend/c03-main-app.mdx
--- sidebar_position: 3 title: Develop Main App --- # Develop Main App In the previous [Experience micro frontend](/guides/topic-detail/micro-frontend/c02-development), an example was used to demonstrate how to create and configure micro frontend sub-applications. Through this chapter, you can further understand how ...
7,417
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail/micro-frontend/c04-communicate.mdx
--- sidebar_position: 4 title: Communicate --- # Communicate ## Props In Modern.js, the sub-application will be wrapped into a React component, and the purpose of communicating between the main application and the sub-application can be achieved directly by passing'props' to the React component. ```tsx title=Main: ...
7,418
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail/micro-frontend/c05-mixed-stack.mdx
--- sidebar_position: 5 title: Mixed Stack --- # Mixed Stack The Modern.js micro frontend scheme is based on the [Garfish](https://garfishjs.org/) package and provides some more out-of-the-box usage. When your main application and sub-application are not all Modern.js applications, you can refer to this document. 1...
7,419
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail/model/_category_.json
{ "label": "Reduck State Manage", "position": 1 }
7,420
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail/model/auto-actions.mdx
--- sidebar_position: 6 title: Automatically Actions --- # Automatically Generated Actions In the [Quick Start](/guides/topic-detail/model/quick-start), we implemented the simplest counter model, which still required 10 lines of code. In fact, Modern.js supports automatically generating commonly used actions based on ...
7,421
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail/model/computed-state.mdx
--- sidebar_position: 4 title: Derived State --- # Derived State In some scenarios, components need to perform further calculations on the State in Model before they can be used in the components. This logic can be directly written in the component or implemented through derived states in Model. Derived states are de...
7,422
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail/model/define-model.mdx
--- sidebar_position: 2 title: Define Model --- # Define a Model In the previous section, we demonstrated how to create a Model for a simple counter application. In this section, we will provide a detailed introduction on how to create a Model. We can create a Model using the `model` API. For example, `model('foo')` ...
7,423
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail/model/faq.mdx
--- sidebar_position: 13 title: FAQ --- # FAQ ## Browser Compatibility The compiled build artifacts of Reduck use ES6 syntax by default. If you need to support older versions of browsers, please include all packages under the `@modern-js-reduck` namespace in your application's build process. :::info Additional Info...
7,424
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail/model/manage-effects.mdx
--- sidebar_position: 5 title: Management Effect --- # Management Effect The actions in the model must be pure functions and cannot have any side effects during execution. However, in real-world scenarios, we often encounter many side effects, such as: requesting data from an HTTP API to obtain state data, or modifyi...
7,425
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail/model/model-communicate.mdx
--- sidebar_position: 7 title: Model Communication --- # Model Communication Model communication refers to communication between different Models, as well as communication between Effects and Actions within the same Model. ## Communication between Models Models are not isolated from each other and can communicate w...
7,426
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail/model/performance.mdx
--- sidebar_position: 8 title: Performance Optimization --- # Performance Optimization Reduck has already done a lot of performance optimization work internally, so performance issues generally do not need to be considered. However, when performance is more sensitive, or when encountering performance issues, you can c...
7,427
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail/model/quick-start.mdx
--- sidebar_position: 1 title: Quick Start --- # Quick Start import ReduckMigration from "@site-docs-en/components/reduck-migration" <ReduckMigration /> [Reduck](https://github.com/web-infra-dev/reduck) is a state management library developed by the Modern.js team that follows the MVC pattern. Its underlying state s...
7,428
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail/model/redux-integration.mdx
--- sidebar_position: 11 title: Ecosystem Integration --- # Redux Ecosystem Integration Reduck is based on Redux, so you can use libraries from the [Redux ecosystem](https://redux.js.org/introduction/ecosystem) to enhance its functionality. APIs like [`Provider`](/apis/app/runtime/model/Provider), [`createApp`](/apis/...
7,429
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail/model/test-model.mdx
--- sidebar_position: 9 title: Test Model --- # Test Model Testing is crucial for the stability of code. Here's an example using the `countModel` from [Quick Start](/guides/topic-detail/model/quick-start) to demonstrate how to perform unit testing on a Model in Modern.js. To use the testing feature, you need to first...
7,430
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail/model/typescript-best-practice.mdx
--- sidebar_position: 10 title: TS Best Practices --- # TS Best Practices Reduck provides excellent support for TypeScript, and in most cases, you can get API type prompts directly without any extra work. In this section, we will provide additional information on other usage scenarios. ## Defining the State Type of t...
7,431
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail/model/use-model.mdx
--- sidebar_position: 3 title: Use Models --- # Use Models ## Using Models in Components ### Using as Global State `useModel` can be used to obtain the State, Actions, and other information of the Model. When the State of the Model is modified by Actions, any other components that use the Model will automatically r...
7,432
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/topic-detail/model/use-out-of-modernjs.mdx
--- sidebar_position: 12 title: Using Reduck Separately --- # Using Reduck Separately When integrating Reduck separately from Modern.js, the following modifications need to be made: 1. Install the Reduck related packages Install the Reduck package in the project: `@modern-js-reduck/react`. 2. Import package names f...
7,433
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/troubleshooting/_category_.json
{ "label": "FAQ", "position": 10, "collapsed": false }
7,434
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/troubleshooting/builder.mdx
--- sidebar_position: 3 --- # Build FAQ If you encounter build-related problems, you can refer to the following documents: ## General FAQ Please refer to [Modern.js Builder - General FAQ](https://modernjs.dev/builder/en/guide/faq/general.html), which contains some general questions about concepts, such as: - The r...
7,435
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/troubleshooting/cli.mdx
--- sidebar_position: 2 --- # CLI FAQ ### Unable to pass command line arguments correctly when using pnpm? There are some differences between pnpm v6 and pnpm v7 in how they execute commands, and the following should be noted: pnpm v7: When using pnpm to call the commands in `package.json`, if you need to pass par...
7,436
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/guides/troubleshooting/dependencies.mdx
--- sidebar_position: 1 --- # Dependencies FAQ ### How to check the actual installed version of a dependency in the project? You can use the `ls` command provided by the package manager to view the version of the dependency in the project. Here are some basic examples. For detailed usage, please refer to the docume...
7,437
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/tutorials
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/tutorials/examples/_category_.json
{ "label": "Examples", "position": 3, "collapsed": false }
7,438
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/tutorials
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/tutorials/examples/csr-auth.mdx
--- title: Route Authorization --- # Route Authorization Modern.js defaults to the convention-based routing based on React Router 6. For more details, please refer to [Routing](/guides/basic-features/routes.html#routing-scheme). In a web application, if there are multiple routes, we may need to authorize access to s...
7,439
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/tutorials
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/tutorials/first-app/_category_.json
{ "label": "Tutorial", "position": 2, "collapsed": false }
7,440
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/tutorials
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/tutorials/first-app/c01-start.mdx
--- title: Create Project --- # Create Project Starting from this chapter, we will enter the practical tutorial section. In the practical tutorial, we will start with environment preparation, starting from simple to complex, building a real project step by step. ## Environment preparation import Prerequisites from "...
7,441
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/tutorials
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/tutorials/first-app/c02-component.mdx
--- title: Add UI Components --- # Add UI Components In the previous chapter, we learned how to initialize a project and use configuration to modify the default behavior of Modern.js. In this chapter, we continue to use the project code of the previous chapter and continue to improve the point of contact list. In o...
7,442
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/tutorials
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/tutorials/first-app/c03-css.mdx
--- title: Add Style --- # Add Style import { Tabs, Tab as TabItem } from '@theme'; In the previous chapter, we learned how to use components from the third-party library. In this chapter, we will learn how to implement UI components. ## JS components using CSS First of all, we want to control the display of cont...
7,443
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/tutorials
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/tutorials/first-app/c04-routes.mdx
--- title: Add Client Route --- # Add Client Route import { Tabs, Tab as TabItem } from "@theme"; In the previous chapter, we learned how to create UI components and add styles. In this chapter, we will learn how to add **Client Route**. Previously we have added the Archive button to the point of contact list, next...
7,444
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/tutorials
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/tutorials/first-app/c05-loader.mdx
--- title: Add Loader --- # Add Loader In the previous chapter, we learned how to add client route. In this chapter, we will learn how to add **Loader** to the routing component. By far, we have provided data to components through hardcoding. If you want to get data from the remote, you usually use `useEffect` to do...
7,445
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/tutorials
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/tutorials/first-app/c06-model.mdx
--- title: Add Model --- # Add Model In the previous chapter, we changed the hardcoding `mockData` to load from Data Loader. In this chapter, we will further implement the functions of the project, such as the implementation of the function of the **Archive** button to put the point of contact archive. Therefore, w...
7,446
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/tutorials
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/tutorials/first-app/c07-container.mdx
--- title: Add Container --- # Add Container import { Tabs, Tab as TabItem } from "@theme"; In the previous chapter, we initially introduced the **model** to split this part of the logic from the UI component. The `page.tsx` no longer contains UI-independent business logic implementation details, and only needs to us...
7,447
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/tutorials
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/tutorials/first-app/c08-entries.mdx
--- title: Add Application Entry --- # Add Application Entry In the last chapter, we basically completed the development of the point of contact list application, introduced the usage of some functions in the Modern.js, and recommended best practices. In this chapter, we will describe how to add a new entry to the ap...
7,448
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/tutorials
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/tutorials/foundations/_category_.json
{ "label": "Basic", "position": 1, "collapsed": false }
7,449
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/tutorials
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/en/tutorials/foundations/introduction.mdx
--- title: Introduction sidebar_position: 1 --- # Introduction Welcome to Modern.js tutorials! After reading this section, you will have an initial understanding of Modern.js and use Modern.js to create your first application. ## What is Modern.js? If you don't know Modern.js yet, please can read [Modern.js Introd...
7,450
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/index.md
--- pageType: home --- # Modern.js - 基于 React 的渐进式 Web 开发框架
7,451
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/commands.mdx
--- sidebar_position: 1 --- # 命令 Modern.js 内置了一些命令,可以帮助你快速启动开发服务器、构建生产环境代码等。 通过本章节,你可以了解到 Modern.js 内置的命令有哪些,以及如何使用这些命令。 ## modern dev `modern dev` 命令用于启动一个本地开发服务器,对源代码进行开发环境编译。 ```bash Usage: modern dev [options] Options: -e --entry <entry> 指定入口,只编译特定的页面 -c --config <config> 指定配置文件路径,可以为相对路径或绝对路径 -h, ...
7,452
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/hooks/_category_.json
{ "label": "文件约定", "position": 2, "collapsed": false }
7,453
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/hooks/modern-config.mdx
--- title: modern.config.[tj]s sidebar_position: 8 --- # modern.config.[tj]s Modern.js 配置文件, 通过该文件可以对当前项目的各个方面进行个性化配置。 了解配置的具体用法,请参考[配置使用](/configure/app/usage)。
7,454
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/hooks/shared.mdx
--- title: shared/ sidebar_position: 5 --- # shared/ 共享源码目录。当项目在 `api/`、`server/`、`src/` 下有公共代码时,可将这些代码放到 `shared` 目录下,而不是直接引用。
7,455
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/hooks
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/hooks/api/_category_.json
{ "label": "api/", "position": 2 }
7,456
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/hooks
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/hooks/api/api.mdx
--- title: '**/*.[tj]s' sidebar_position: 1 --- # **/*.[tj]s 在 [BFF 函数写法](/guides/advanced-features/bff/type.html#函数写法)下,声明 API 路由的文件。除了[某些约定文件](/apis/app/hooks/api/api#白名单)外,`api` 目录下的文件会被注册为接口的路由。 :::info 使用 `api` 目录需要开启 BFF 功能,需要在项目下执行 new 命令启用「BFF」功能。 该文件支持使用 `js` 或 `ts` 语言,但必须使用 `esm` 语法导出函数。 ::: ## 该文件约定路由如...
7,457
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/hooks
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/hooks/api/app.mdx
--- title: _app.[tj]s sidebar_position: 2 --- # _app.[tj]s 在 [BFF 函数写法](/guides/advanced-features/bff/type.html#函数写法)下,该文件可以为 BFF 函数添加前置中间件。 :::note 具体示例请参考 [hook](/apis/app/runtime/bff/hook) :::
7,458
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/hooks
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/hooks/api/lambda.mdx
--- title: lambda/*.[tj]s sidebar_position: 3 --- # lambda/*.[tj]s 在 [BFF 框架写法](/guides/advanced-features/bff/type.html#框架写法)下,声明 API 路由的文件。除了[某些约定文件](/apis/app/hooks/api/lambda#白名单)外,`lambda/` 目录下的文件会被注册为接口的路由。 :::info 使用 `api` 目录需要开启 BFF 功能,需要在项目下执行 new 命令启用「BFF」功能。 ::: :::tip 该文件支持使用 `js` 或 `ts` 语言,但必须使用 `esm` 语...
7,459
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/hooks
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/hooks/api/test.mdx
--- title: test.[tj]s sidebar_position: 4 --- # test.[tj]s The BFF test file of the application supports writing test cases in files with the suffix `.test.[tj]sx?` under the `api/` directory. :::info Enabling unit testing and integration testing requires running the new command to enable the "Unit Testing/Integratio...
7,460
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/hooks
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/hooks/config/_category_.json
{ "label": "config/", "position": 6 }
7,461
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/hooks
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/hooks/config/html.mdx
--- title: html/ sidebar_position: 1 --- # html/ 通过 `config/html` 目录可以在内部默认 html 模板的不同位置注入自定义的 html 片段。 具体使用方式请参考: [自定义 HTML](/guides/basic-features/html)
7,462
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/hooks
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/hooks/config/icon.mdx
--- title: icon/ sidebar_position: 2 --- # icon/ ## Favicon 当项目根目录的 `config` 目录下存在 `favicon.*` 文件时,Modern.js 会自动将该文件设置到 [html.favicon](/configure/app/html/favicon) 配置项中,用于生成页面的 favicon 图标: ``` ./config └── favicon.ico ``` 构建完成后,可以看到 HTML 中自动生成了以下标签: ```html <link rel="icon" href="/favicon.ico" /> ``` ### 查找顺序 在...
7,463
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/hooks
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/hooks/config/mock.mdx
--- title: mock/ sidebar_position: 5 --- # mock/ 当项目目录下存在 `config/mock/index.js` 时,Modern.js 在开发环节将自动开启 Mock 服务。
7,464
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/hooks
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/hooks/config/public.mdx
--- title: public/ sidebar_position: 3 --- # public/ `public/` 目录中可以放置任意格式的静态资源文件,文件会被服务端部署到对应的应用域名下。 ## 说明 文件路由基于目录结构的约定,其中,`public/` 为根目录,对应 Web 应用根路径。 例如 `config/public/sdk/index.js` 文件,在部署后将会被部署在 `${domain}/sdk/index.js` 下。 ## 场景 例如 `robots.txt`,`auth.xml` 等第三方系统需要的认证文件。 或者是给其他业务方(要求路由不变)的 SDK,也可以是无需入口的 HTML...
7,465
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/hooks
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/hooks/config/storybook.mdx
--- title: storybook/ sidebar_position: 7 --- # storybook/ Modern.js 支持使用 Storybook 进行调试,当需要对 Storybook 进行配置时,需要在项目 config/storybook 目录进行配置。 Storybook 配置请查看:[Storybook 配置](https://storybook.js.org/docs/react/configure/overview) :::info 使用 Storybook 进行调试需要提前在项目下执行 new 命令启用「Visual Testing (Storybook)」模式功能。 ::: ### ...
7,466
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/hooks
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/hooks/config/upload.mdx
--- title: upload/ sidebar_position: 4 --- # upload/ `upload/` 目录中可以放置任意格式的静态资源文件。 ## 说明 在开发环境下,该目录下的静态资源文件会被托管在 `/upload` 路径下。构建应用产物后,该目录下的文件会被复制到产物目录中。 该文件约定主要用于开发者使用插件,主动上传静态资源文件到 CDN。 ## 场景 例如 `google-analysis.js` 等项目自用的 SDK(通常需要 HTTP 缓存)。 图片、字体文件、通用 CSS 等。 ## 代码压缩 如果目录下的文件是一个 `.js` 文件,在生产环境构建时,会自动对其进行代码压缩...
7,467
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/hooks
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/hooks/server/_category_.json
{ "label": "server/", "position": 3 }
7,468
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/hooks
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/hooks/server/index_.mdx
--- title: index.[tj]s sidebar_position: 1 --- # index.[tj]s 扩展 Modern.js Web Server 的文件,在此文件中可以给 Modern.js 工程启动的 Web Server 添加 [Hook](/apis/app/runtime/web-server/hook) 或 [Middleware](/apis/app/runtime/web-server/middleware)。 可以对请求和响应进行拦截处理,鉴权与角色、请求预处理、异常兜底等。也可在内置处理逻辑(包括路由匹配、资源寻址、头部注入、页面渲染,静态 Web 托管)插入特定的业务逻辑。
7,469
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/hooks
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/hooks/server/test.mdx
--- title: test.[tj]s sidebar_position: 2 --- # test.[tj]s 自定义 Web Server 测试目录。 应用支持对自定义 Web Server 逻辑进行测试,可直接在项目 `server/` 目录下创建后缀为 `.test.[tj]s` 文件进行编写测试用例。 :::info 使用单元测试、集成测试需要提前在项目下执行 new 命令启用「单元测试 / 集成测试」功能。 :::
7,470
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/hooks
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/hooks/src/_category_.json
{ "label": "src/", "position": 1 }
7,471
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/hooks
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/hooks/src/app.mdx
--- title: App.[tj]sx sidebar_position: 1 --- # App.[tj]sx 应用使用[自控路由](/guides/basic-features/routes.html#self-controlled-routing)时的入口标识符。 `App.[tj]sx` 并不是实际的应用入口,Modern.js 会自动生成真正的构建打包的入口文件, 内容大致如下: ```js import React from 'react'; import ReactDOM from 'react-dom/client'; import { createApp, bootstrap } from '@moder...
7,472
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/hooks
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/hooks/src/index_.mdx
--- title: index.[tj]s sidebar_position: 4 --- # index.[tj]s 应用使用自定义 `bootstrap` 时的入口标识。 通常情况下 [`App.[tj]sx`](/apis/app/hooks/src/app) 钩子文件已经能满足我们的需求,当我们需要在 `bootstrap` 之前添加自定义行为或者完全接管 webpack 打包入口时,可以在 `src` 或者入口目录下放置 `index.[tj]s`。 下面有分两种情况进行讨论: ## 在 bootstrap 之前添加自定义行为 只需要 `src/index.[tj]s` 默认导出函数: ```js title=...
7,473
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/hooks
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/hooks/src/pages.mdx
--- title: pages/ sidebar_position: 3 --- # pages/ 应用使用 [`Pages` 入口](https://modernjs.dev/v1/docs/guides/usages/entries#pages-%E5%85%A5%E5%8F%A3)时的入口标识。 :::info 兼容 Modern.js 1.0 `Pages` 入口,推荐使用[约定式路由](guides/basic-features/routes.html#约定式路由)。 ::: 当项目结构为 `Pages 入口`类型时, 会分析 `src/pages` 目录下的文件得到客户端路由配置。 举例说明,例如以下目录结构:...
7,474
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/hooks
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/hooks/src/routes.mdx
--- title: routes/ sidebar_position: 2 --- # routes/ 应用使用[约定式路由](guides/basic-features/routes.html#约定式路由)时的入口标识。 约定式路由以 `routes/` 为约定的入口, 会分析 `src/routes` 目录下的文件得到客户端路由配置。 任何在 `src/routes` 下的 `layout.[tj]sx` 和 `page.[tj]sx` 都会作为应用的路由: ```bash {3,4} . └── routes ├── layout.tsx ├── page.tsx └── user ...
7,475
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/hooks
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/hooks/src/server.mdx
--- title: '*.[server|node].[tj]sx' sidebar_position: 8 --- # *.[server|node].[tj]sx 应用项目中使用,用于放置服务端代码,当 `*.tsx` 和 `*.[server|node].tsx` 共存时,SSR 在服务端执行渲染时,会优先使用 `*.[server|node].tsx` 文件,而不是 `*.tsx` 文件。
7,476
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/hooks
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/hooks/src/stories.mdx
--- title: '**/*.stories.[tj]sx' sidebar_position: 7 --- # **/*.stories.[tj]sx 应用项目 Storybook 调试文件。 可以在项目源码目录 `src/` 下创建 `*.stories.(js|jsx|ts|tsx|mdx)` 格式的文件作为 Storybook 的调试文件。 在项目下执行 `npm run dev story` 命令,支持使用这些文件在 Storybook 中对相关内容进行调试。 :::info 使用 Storybook 需要提前在项目下执行 new 命令启用「Visual Testing (Storybook)」模式。 :::...
7,477
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/hooks
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/hooks/src/test.mdx
--- title: '**/*.test.[tj]sx?' sidebar_position: 6 --- # **/*.test.[tj]sx? 应用项目测试文件。 应用项目支持在项目源码目录(src)下创建后缀为 `.test.[tj]sx?` 文件进行编写测试用例。 :::info 使用单元测试、集成测试需要提前在项目下执行 new 命令启用「单元测试 / 集成测试」功能。 :::
7,478
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/runtime/_category_.json
{ "label": "运行时", "position": 3, "collapsed": false }
7,479
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/runtime
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/runtime/app/_category_.json
{ "label": "APP", "position": 4 }
7,480
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/runtime
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/runtime/app/define-config.mdx
--- sidebar_position: 1 title: defineConfig --- # defineConfig 用于动态配置应用。 ## 使用姿势 ```ts import { defineConfig } from '@modern-js/runtime'; ``` Runtime 配置通常可以在 `modern.config.js` 的 `runtime` 空间下配置,如 [router](/configure/app/runtime/router) 配置。 `modern.config.js` 中的配置是构建时确定的,如果一些配置参数是运行时获取的,或者配置参数是来自于源码中的一个模块(如组件),就需要...
7,481
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/runtime
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/runtime/bff/_category_.json
{ "label": "BFF", "position": 8 }
7,482
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/runtime
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/runtime/bff/hook.mdx
--- title: hook --- # hook 用于在 BFF 函数写法下添加框架中间件,添加的中间件的执行会在 BFF 函数定义的路由之前。 ## 使用姿势 根据使用的框架拓展插件,从对应的命名空间中导出: ```ts import { hook } from '@modern-js/runtime/{namespace}'; ``` ## 函数签名 ```ts type HookOptions = { addMiddleware: string | function; }; function hook(options: HookOptions): void; ``` ### 参数 - `options...
7,483
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/runtime
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/runtime/bff/use-context.mdx
--- title: useContext --- # useContext 用于在一体化 BFF 函数中获取请求上下文。 ## 使用姿势 根据使用的框架拓展插件,从对应的命名空间中导出: ```ts import { useContext } from '@modern-js/runtime/{namespace}'; ``` ## 函数签名 `function useContext(): any` ## 示例 开发者可以通过 `context` 获取更多的请求信息,例如获取请求 UA(示例为使用 koa 框架时): ```ts import { useContext } from '@modern-js/run...
7,484
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/runtime
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/runtime/core/_category_.json
{ "label": "核心", "position": 3 }
7,485
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/runtime
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/runtime/core/bootstrap.mdx
--- title: bootstrap --- # bootstrap 用于启动和挂载应用,通常情况下不做手动调用。只有在使用[自定义 Bootstrap](/guides/concept/entries#自定义-bootstrap) 时,才需要使用该 API。 ## 使用姿势 ```ts import ReactDOM from 'react-dom/client'; import { bootstrap } from '@modern-js/runtime'; bootstrap(App, 'root', undefined, ReactDOM); ``` ## 函数签名 ```ts type BootStrap<...
7,486
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/runtime
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/runtime/core/create-app.mdx
--- title: createApp --- # createApp 用于创建自定义入口,定制运行时插件。只有在使用[自定义 App](/guides/concept/entries#自定义-app) 时,才需要使用该 API。 ## 使用姿势 ```ts import { createApp } from '@modern-js/runtime'; ``` ## 函数签名 ```ts import type { Plugin } from '@modern-js/runtime'; function createApp(options: { plugins: Plugin[] }): React.Component...
7,487
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/runtime
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/runtime/core/use-loader.mdx
--- title: useLoader --- # useLoader 一个同构的 API,通常会用来做异步请求。当 SSR 的时候,服务端使用 `useLoader` 预加载数据,同时浏览器端也会复用这部分数据。 :::tip 在使用 Rspack 作为打包工具时,暂不支持使用 useLoader API。 ::: ## 使用姿势 ```ts import { useLoader } from '@modern-js/runtime'; ``` ## 函数签名 ```ts type LoaderFn = (context: runtimeContext) => Promise<unknow>; type Option...
7,488
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/runtime
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/runtime/core/use-module-apps.mdx
--- title: useModuleApps --- # useModuleApps 返回所有微前端子应用的 React 组件,用于可自由控制路由。 ## 使用姿势 ```tsx import { useModuleApps } from '@modern-js/plugin-garfish/runtime'; ``` ## 函数签名 `function useModuleApps(): Record<string, React.FC<any>>` 分别返回包裹每个子应用后的 React 组件。 ## 示例 需要先配置微前端子应用信息。 import EnableMicroFrontend from "@sit...
7,489
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/runtime
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/runtime/core/use-runtime-context.mdx
--- title: useRuntimeContext --- # useRuntimeContext 该函数主要用于获取 Runtime 上下文,只能在函数组件中使用。 ## 使用姿势 ```tsx import { useRuntimeContext } from '@modern-js/runtime'; export function App() { const runtimeContext = useRuntimeContext(); return <div>Hello World</div>; } ``` ## 函数签名 ```ts type RuntimeContext = { request...
7,490
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/runtime
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/runtime/model/Provider.mdx
--- sidebar_position: 8 title: Provider --- # Provider import ReduckTip from "@site-docs/components/reduck-tip" <ReduckTip /> `Provider` 是一个组件,它将 Reduck 的 Store 注入到应用的组件树中,使组件树内部的组件可以访问 Model。一般情况下,`Provider` 会定义在组件树的最顶层。 ## 函数签名 ```ts interface ProviderProps { store?: ReduckStore; config?: AppConfig; } ``` #...
7,491
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/runtime
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/runtime/model/_category_.json
{ "label": "Model", "position": 6 }
7,492
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/runtime
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/runtime/model/auto-actions.mdx
--- sidebar_position: 6 title: Auto actions --- # Auto actions import ReduckTip from "@site-docs/components/reduck-tip" <ReduckTip /> Reduck 可以根据 State 的类型,自动生成相应的 Actions,为修改 State 提供便利。 :::tip 提示 可通过 [`runtime.state.autoActions`](/configure/app/runtime/state#autoactions) 关闭 auto actions 功能。 ::: ## 示例 ### 基础数据类...
7,493
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/runtime
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/runtime/model/connect.mdx
--- sidebar_position: 5 title: connect --- # connect import ReduckTip from "@site-docs/components/reduck-tip" <ReduckTip /> :::tip 提示 Reduck 原始类型较为复杂,以下涉及类型定义的地方,展示的是简化后的类型信息。原始类型见 [**connect**](https://github.com/web-infra-dev/reduck/blob/main/packages/react/src/connect.ts)。 ::: `connect` 功能上同 `useModel` 一致,是对应的 ...
7,494
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/runtime
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/runtime/model/create-app.mdx
--- sidebar_position: 11 title: createApp --- # createApp import ReduckTip from "@site-docs/components/reduck-tip" <ReduckTip /> Reduck 内部默认会使用 `createApp` 创建一个全局应用,如果整个应用只需要共享一个 Store,那么是不需要使用 `createApp` 的。只有当需要在应用局部创建共享 Store 时,才需要使用 `createApp`。 :::caution 注意 注意 `@modern-js/runtime/model` 中导出的 `createApp` 用于管理状...
7,495
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/runtime
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/runtime/model/create-store.mdx
--- sidebar_position: 10 title: createStore --- # createStore import ReduckTip from "@site-docs/components/reduck-tip" <ReduckTip /> `createStore` 用于创建一个 Store 对象。Reduck 的 Store 基于 Redux 的 [Store](https://redux.js.org/api/store) 实现,用于存储应用的状态,同时提供一组用于管理状态和 Model 的方法。 一般情况下,不需要使用这个 API,只有需要完全掌控 Store 的创建时,才会使用这个 API。...
7,496
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/runtime
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/runtime/model/handle-effect.mdx
--- sidebar_position: 7 title: handleEffect --- # handleEffect import ReduckTip from '@site-docs/components/reduck-tip'; <ReduckTip /> 一个异步函数类型的 Effect,通常有三种需要处理的状态: 请求中、请求成功、请求处理失败。这些状态处理的方式,就是编写对应的 Action 函数(pending、fulfilled、rejected)。 借助 `handleEffect` API,我们可以生成默认的 Action 函数来处理异步请求各个阶段的不同结果。`handleEffect` 生成的...
7,497
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/runtime
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/runtime/model/model_.mdx
--- sidebar_position: 1 title: model --- # model import ReduckTip from '@site-docs/components/reduck-tip'; <ReduckTip /> :::tip 提示 Reduck 原始类型较为复杂,以下涉及类型定义的地方,展示的是简化后的类型信息。原始类型见 [**model**](https://github.com/web-infra-dev/reduck/blob/main/packages/store/src/model/model.ts)。 ::: ## model 用于创建管理应用状态的 Model。 `fun...
7,498
0
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/runtime
petrpan-code/web-infra-dev/modern.js/packages/document/main-doc/docs/zh/apis/app/runtime/model/use-local-model.mdx
--- sidebar_position: 4 title: useLocalModel --- # useLocalModel import ReduckTip from "@site-docs/components/reduck-tip" <ReduckTip /> 用于把 Model 中的 State 作为局部状态使用,效果类似 React 的 `useState`。`useLocalModel` API 形式上与 `useModel` 完全一致。具体使用请参考 [`useModel`](./use-model.mdx)。 #### 示例 ```tsx function Container() { const [...
7,499