-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
49 changed files
with
11,358 additions
and
1,379 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,16 @@ | ||
# 实现异步数据源 | ||
# Asynchronous Data Sources | ||
|
||
异步数据源管理,核心体现在[Field](https://core.formilyjs.org/api/models/field)模型中的 dataSource 属性,我们可以在 effects 中修改 Field 的 dataSource,也可以在 reactions 中修改 dataSource 属性。 | ||
Asynchronous data source management, the core is reflected in the dataSource property of the [Field](https://core.formilyjs.org/api/models/field) model. We can modify the dataSource of the Field in effects, or modify the dataSource property in reactions. | ||
|
||
如果字段组件内部(比如 Select)有消费 dataSource 属性,当 dataSource 发生变化时,对应组件会自动重渲染。 | ||
If the field component (such as Select) has a consumer dataSource property, when the dataSource changes, the corresponding component will automatically re-render. | ||
|
||
<Alert> | ||
注意:如果是业务自定义组件,请手动映射dataSource到自定义组件中,可以使用 <a href="https://react.formilyjs.org/api/shared/connect">connect</a>,也可以使用 <a href="https://react.formilyjs.org/api/shared/observer">observer</a> + <a href="https://react.formilyjs.org/api/hooks/use-field">useField</a> | ||
Note: If it is a business custom component, please manually map the dataSource to the custom component, you can use <a href="https://react.formilyjs.org/api/shared/connect">connect</a> or <a href="https://react.formilyjs.org/api/shared/observer">observer</a> + <a href="https://react.formilyjs.org/api/hooks/use-field">useField</a> | ||
</Alert> | ||
|
||
具体案例可以参考: | ||
Specific cases can refer to: | ||
|
||
- [Select](https://antd.formilyjs.org/components/select) | ||
- [TreeSelect](https://antd.formilyjs.org/components/tree-select) | ||
- [Cascader](https://antd.formilyjs.org/components/cascader) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# 实现异步数据源 | ||
|
||
异步数据源管理,核心体现在[Field](https://core.formilyjs.org/api/models/field)模型中的 dataSource 属性,我们可以在 effects 中修改 Field 的 dataSource,也可以在 reactions 中修改 dataSource 属性。 | ||
|
||
如果字段组件内部(比如 Select)有消费 dataSource 属性,当 dataSource 发生变化时,对应组件会自动重渲染。 | ||
|
||
<Alert> | ||
注意:如果是业务自定义组件,请手动映射dataSource到自定义组件中,可以使用 <a href="https://react.formilyjs.org/api/shared/connect">connect</a>,也可以使用 <a href="https://react.formilyjs.org/api/shared/observer">observer</a> + <a href="https://react.formilyjs.org/api/hooks/use-field">useField</a> | ||
</Alert> | ||
|
||
具体案例可以参考: | ||
|
||
- [Select](https://antd.formilyjs.org/components/select) | ||
- [TreeSelect](https://antd.formilyjs.org/components/tree-select) | ||
- [Cascader](https://antd.formilyjs.org/components/cascader) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
# 按需打包 | ||
|
||
## 基于Umi开发 | ||
|
||
#### 安装 `babel-plugin-import` | ||
|
||
```shell | ||
npm install babel-plugin-import --save-dev | ||
``` | ||
或者 | ||
```shell | ||
yarn add babel-plugin-import --dev | ||
``` | ||
|
||
#### 插件配置 | ||
修改 `.umirc.js`或 `.umirc.ts` | ||
|
||
```js | ||
export default { | ||
extraBabelPlugins: [['babel-plugin-import', {"libraryName": "@formily/antd", "libraryDirectory": "lib"}]], | ||
}; | ||
``` | ||
|
||
## 基于create-react-app开发 | ||
|
||
首先我们需要对`create-react-app`的默认配置进行自定义,这里我们使用 [react-app-rewired](https://github.com/timarney/react-app-rewired) (一个对 `create-react-app` 进行自定义配置的社区解决方案)。 | ||
引入 `react-app-rewired` 并修改 `package.json` 里的启动配置。由于新的 [react-app-rewired@2.x](https://github.com/timarney/react-app-rewired#alternatives) 版本的关系,你还需要安装 [customize-cra](https://github.com/arackaf/customize-cra)。 | ||
|
||
```shell | ||
$ npm install react-app-rewired customize-cra --save-dev | ||
``` | ||
或者 | ||
```shell | ||
$ yarn add react-app-rewired customize-cra --dev | ||
``` | ||
|
||
修改 `package.json` | ||
```diff | ||
"scripts": { | ||
- "start": "react-scripts start", | ||
+ "start": "react-app-rewired start", | ||
- "build": "react-scripts build", | ||
+ "build": "react-app-rewired build", | ||
- "test": "react-scripts test", | ||
+ "test": "react-app-rewired test", | ||
} | ||
``` | ||
然后在项目根目录创建一个 `config-overrides.js` 用于修改默认配置。 | ||
|
||
```js | ||
module.exports = function override(config, env) { | ||
// do stuff with the webpack config... | ||
return config; | ||
}; | ||
``` | ||
#### 安装 babel-plugin-import | ||
|
||
```shell | ||
npm install babel-plugin-import --save-dev | ||
``` | ||
或者 | ||
```shell | ||
yarn add babel-plugin-import --dev | ||
``` | ||
|
||
修改`config-overrides.js` | ||
|
||
```diff | ||
+ const { override, fixBabelImports } = require('customize-cra'); | ||
|
||
- module.exports = function override(config, env) { | ||
- // do stuff with the webpack config... | ||
- return config; | ||
- }; | ||
+ module.exports = override( | ||
+ fixBabelImports('import', { | ||
+ libraryName: '@formily/antd', | ||
+ libraryDirectory: 'lib' | ||
+ }), | ||
+ ); | ||
``` | ||
|
||
|
||
## 在Webpack中使用 | ||
|
||
#### 安装 babel-plugin-import | ||
|
||
```shell | ||
npm install babel-plugin-import --save-dev | ||
``` | ||
或者 | ||
```shell | ||
yarn add babel-plugin-import --dev | ||
``` | ||
|
||
修改 `.babelrc` 或者 babel-loader | ||
|
||
```json | ||
{ | ||
"plugins": [ | ||
["import", { "libraryName": "@formily/antd", "libraryDirectory": "lib"}] | ||
] | ||
} | ||
``` | ||
|
||
更多配置请参考 [babel-plugin-import](https://github.com/ant-design/babel-plugin-import) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.