Skip to content

Commit dd1787b

Browse files
author
chenbin92
authored
Merge pull request #3236 from alibaba/release-next
2 parents caed352 + 9699162 commit dd1787b

File tree

62 files changed

+2022
-371
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+2022
-371
lines changed

.eslintrc.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,7 @@ module.exports = {
3838
files: ['**/*.ts', '**/*.tsx'],
3939
},
4040
],
41+
env: {
42+
"jest": true
43+
}
4144
};

.github/workflows/ci.yml

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,20 @@ on: [push]
44

55
jobs:
66
build:
7-
87
runs-on: ubuntu-latest
9-
108
strategy:
119
matrix:
1210
node-version: [10.x]
13-
1411
steps:
15-
- uses: actions/checkout@v2
16-
- name: Use Node.js ${{ matrix.node-version }}
17-
uses: actions/setup-node@v1
18-
with:
19-
node-version: ${{ matrix.node-version }}
20-
- run: npm run setup
21-
- run: npm run lint
22-
- run: npm run dependency:check
23-
env:
24-
CI: true
12+
- uses: actions/checkout@v2
13+
- name: Use Node.js ${{ matrix.node-version }}
14+
uses: actions/setup-node@v1
15+
with:
16+
node-version: ${{ matrix.node-version }}
17+
- run: npm run setup
18+
- run: npm run dependency:check
19+
- run: npm run lint
20+
- run: npm run test
21+
- run: npm run coverage
22+
env:
23+
CI: true

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,6 @@ examples/*/.ice
1919
docs/.vuepress/dist/
2020

2121
build
22+
coverage
23+
24+
.idea

codecov.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
comment:
3+
layout: "reach, diff, flags, files"
4+
behavior: default
5+
require_changes: false
6+
require_base: no
7+
require_head: yes
8+
branches:
9+
- "master"
10+
11+
coverage:
12+
status:
13+
project:
14+
default:
15+
threshold: 90%
16+
patch: off

docs/guide/basic/build.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,19 @@ icejs 中一般不允许修改该配置。
412412
}
413413
```
414414

415+
### disableRuntime
416+
417+
- 类型:`boolean`
418+
- 默认值:`false`
419+
420+
禁用运行时的能力,如需关闭配置为 `true` 即可。
421+
422+
```json
423+
{
424+
"disableRuntime": true
425+
}
426+
```
427+
415428
## 根据环境区分工程配置
416429

417430
参考 [区分不同环境](/docs/guide/basic/mode.md)

docs/guide/basic/request.md

Lines changed: 75 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ import userService from '@/services/user';
139139

140140
export default function HomePage() {
141141
// 调用 service
142-
const { data, error, isLoading, request } = useRequest(userService.getUser);
142+
const { data, error, loading, request } = useRequest(userService.getUser);
143143

144144
useEffect(() => {
145145
// 触发数据请求
@@ -253,67 +253,89 @@ Response Schema:
253253

254254
### useRequest
255255

256-
* 可以用在 Function Component,使用 useRequest 可以极大的简化对请求状态(error/loading)的管理。
257-
* 可以接收一个 `Object` 或者是 `(...args)=> any` 作为参数。
256+
用在函数式组件中,使用 useRequest 可以极大的简化对请求状态的管理。
258257

259-
#### 传入对象作为参数
258+
#### API
260259

261260
```ts
262-
const { data, loading, error, request } = useRequest(options: RequestConfig);
261+
const {
262+
// 请求返回的数据,默认为 undefined
263+
data,
264+
// 请求抛出的异常,默认为 undefined
265+
error,
266+
// 请求状态
267+
loading,
268+
// 手动触发请求,参数会传递给 service
269+
request,
270+
// 当次执行请求的参数数组
271+
params,
272+
// 取消当前请求,如果有轮询,停止
273+
cancel,
274+
// 使用上一次的 params,重新执行请求
275+
refresh,
276+
// 直接修改 data
277+
mutate,
278+
// 默认情况下,新请求会覆盖旧请求。如果设置了 fetchKey,则可以实现多个请求并行,fetches 存储了多个请求的状态
279+
fetches
280+
} = useRequest(service, {
281+
// 默认为 true 即需要手动执行请求
282+
manual,
283+
// 初始化的 data
284+
initialData,
285+
// 请求成功时触发,参数为 data 和 params
286+
onSuccess,
287+
// 请求报错时触发,参数为 error 和 params
288+
onError,
289+
// 格式化请求结果
290+
formatResult,
291+
// 请求唯一标识
292+
cacheKey,
293+
// 设置显示 loading 的延迟时间,避免闪烁
294+
loadingDelay,
295+
// 默认参数
296+
defaultParams,
297+
// 轮询间隔,单位为毫秒
298+
pollingInterval
299+
// 在页面隐藏时,是否继续轮询,默认为 true,即不会停止轮询
300+
pollingWhenHidden,
301+
// 根据 params,获取当前请求的 key
302+
fetchKey,
303+
// 在屏幕重新获取焦点或重新显示时,是否重新发起请求。默认为 false,即不会重新发起请求
304+
refreshOnWindowFocus,
305+
// 屏幕重新聚焦,如果每次都重新发起请求,不是很好,我们需要有一个时间间隔,在当前时间间隔内,不会重新发起请求,需要配置 refreshOnWindowFocus 使用
306+
focusTimespan,
307+
// 防抖间隔, 单位为毫秒,设置后,请求进入防抖模式
308+
debounceInterval,
309+
// 节流间隔, 单位为毫秒,设置后,请求进入节流模式。
310+
throttleInterval,
311+
// 只有当 ready 为 true 时,才会发起请求
312+
ready,
313+
// 在 manual = false 时,refreshDeps 变化,会触发请求重新执行
314+
refreshDeps
315+
});
263316
```
264317

265-
使用示例:
266-
267-
```ts
268-
import { useRequest } from 'ice';
269-
270-
export default function HomePage() {
271-
const { data, error, isLoading, request } = useRequest({
272-
url: '/api/getRepo',
273-
params: {
274-
id: 123
275-
}
276-
});
277-
278-
useEffect(() => {
279-
request();
280-
}, []);
281-
282-
283-
return (
284-
<>Home</>
285-
);
286-
}
287-
```
288-
289-
#### 传入函数作为参数
318+
#### 常用使用方式
290319

291320
```ts
292-
const { data, loading, error, request } = useRequest((...args: any[]) => any);
321+
// 用法 1:传入字符串
322+
const { data, error, loading } = useRequest('/api/repo');
323+
324+
// 用法 2:传入配置对象
325+
const { data, error, loading } = useRequest({
326+
url: '/api/repo',
327+
method: 'get',
328+
});
329+
330+
// 用法 3:传入 service 函数
331+
const { data, error, loading, request } = useRequest((id) => ({
332+
url: '/api/repo',
333+
method: 'get',
334+
data: { id },
335+
});
293336
```
294337
295-
使用示例:
296-
297-
```ts
298-
// src/pages/Home/index.tsx
299-
import { useRequest } from 'ice';
300-
import services from '@/services';
301-
302-
export default function HomePage() {
303-
const { data, error, isLoading, request } = useRequest(services.getRepo);
304-
305-
useEffect(() => {
306-
// 动态传入参数
307-
const id = 123;
308-
request(id);
309-
}, []);
310-
311-
312-
return (
313-
<>Home</>
314-
);
315-
}
316-
```
338+
更多使用方式详见 [ahooks/useRequest](https://ahooks.js.org/zh-CN/hooks/async)
317339
318340
### 请求配置
319341
@@ -378,7 +400,6 @@ const appConfig = {
378400
{
379401
baseURL: '/api',
380402
// ...RequestConfig 其他参数
381-
382403
},
383404
{
384405
// 配置 request 实例名称,如果不配默认使用内置的 request 实例

examples/basic-request/src/pages/Home/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ const BuiltInRequestDemo1 = () => {
66
console.clear();
77

88
async function fetchUser1() {
9-
const data = await request({url: '/user' });
9+
const data = await request({ url: '/user' });
1010
console.log('直接调用 request:', data);
1111
}
1212

1313
async function fetchUser2() {
14-
const data = await request({url: '/user', withFullResponse: true });
14+
const data = await request({ url: '/user', withFullResponse: true });
1515
console.log('调用 request + withFullResponse:', data);
1616
}
1717

18-
const { request: fetchUser3, ...rest } = useRequest({url: '/user'});
18+
const { request: fetchUser3, ...rest } = useRequest({ url: '/user' });
1919
console.log('直接调用 useRequest:', {...rest});
2020

2121
return (
@@ -45,7 +45,7 @@ const BuiltInRequestDemo3 = () => {
4545
console.log('多实例 + 直接调用 request:', data);
4646
}
4747

48-
const { request: fetchUser2, ...rest } = useRequest({url: '/user', instanceName: 'request2'});
48+
const { request: fetchUser2, ...rest } = useRequest({ url: '/user', instanceName: 'request2' });
4949
console.log('多实例 + 调用 useRequest:', {...rest});
5050

5151
return (

examples/basic-store/src/models/.s.svn

Whitespace-only changes.

examples/icestark-child/src/app.ts renamed to examples/icestark-child/src/app.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
import React from 'react';
12
import { createApp, IAppConfig } from 'ice';
23

34
const appConfig: IAppConfig = {
45
app: {
56
rootId: 'ice-container'
67
},
8+
router: {
9+
fallback: <div>加载中...</div>
10+
},
711
logger: {
812
level: 'warn'
913
},

examples/icestark-layout/src/app.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const appConfig: IAppConfig = {
1414
},
1515
router: {
1616
type: 'browser',
17+
fallback: <div>加载中...</div>
1718
},
1819
icestark: {
1920
type: 'framework',

examples/simple/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# simple example
2+
3+
https://github.com/ice-lab/icejs/tree/master/examples

examples/simple/build.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"entry": "src/index.tsx",
3+
"disableRuntime": true,
4+
"plugins": []
5+
}

examples/simple/package.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "example-simple",
3+
"dependencies": {
4+
"ice.js": "^1.0.0",
5+
"react": "^16.4.1",
6+
"react-dom": "^16.4.1"
7+
},
8+
"devDependencies": {
9+
"@types/react": "^16.9.20",
10+
"@types/react-dom": "^16.9.5"
11+
},
12+
"scripts": {
13+
"start": "icejs start",
14+
"build": "icejs build"
15+
},
16+
"engines": {
17+
"node": ">=8.0.0"
18+
}
19+
}

examples/simple/public/favicon.png

4.83 KB
Loading

examples/simple/sandbox.config.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"template": "node",
3+
"container": {
4+
"port": 3333
5+
}
6+
}

examples/simple/src/index.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import React from 'react';
2+
import ReactDOM from 'react-dom';
3+
4+
const App = () => {
5+
return <h2>Hello World</h2>;
6+
};
7+
8+
ReactDOM.render(<App />, document.querySelector('#ice-container'));

examples/simple/tsconfig.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"compileOnSave": false,
3+
"buildOnSave": false,
4+
"compilerOptions": {
5+
"baseUrl": ".",
6+
"outDir": "build",
7+
"module": "esnext",
8+
"target": "es6",
9+
"jsx": "react",
10+
"moduleResolution": "node",
11+
"allowSyntheticDefaultImports": true,
12+
"lib": [
13+
"es6",
14+
"dom"
15+
],
16+
"sourceMap": true,
17+
"allowJs": true,
18+
"rootDir": "./",
19+
"forceConsistentCasingInFileNames": true,
20+
"noImplicitReturns": true,
21+
"noImplicitThis": true,
22+
"noImplicitAny": false,
23+
"importHelpers": true,
24+
"strictNullChecks": true,
25+
"suppressImplicitAnyIndexErrors": true,
26+
"noUnusedLocals": true,
27+
"skipLibCheck": true
28+
}
29+
}

jest.config.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module.exports = {
2+
'coverageDirectory': './coverage/',
3+
'testEnvironment': 'node',
4+
'collectCoverage': true,
5+
'coveragePathIgnorePatterns': [
6+
'<rootDir>/node_modules/'
7+
],
8+
'roots': [
9+
'<rootDir>/packages'
10+
],
11+
'testPathIgnorePatterns': [
12+
'/node_modules/',
13+
'/lib/',
14+
'icejs/bin/'
15+
],
16+
'preset': 'ts-jest'
17+
};

lerna.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "1.4.2",
2+
"version": "1.5.0",
33
"npmClient": "yarn",
44
"useWorkspaces": true,
55
"packages": [

0 commit comments

Comments
 (0)