Skip to content

Commit e0e871b

Browse files
committed
chore: add keepalive
1 parent 6f1d880 commit e0e871b

File tree

6 files changed

+93
-29
lines changed

6 files changed

+93
-29
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ should be named as `use.{{lowerCase}}`, eg. `@rp/use.i18n`.
5252

5353
## Packages
5454

55-
- [@rcp/c.loadingwrapper](packages/c.loadingwrapper) - A component for easy create loading mask
56-
- [@rcp/hoc.mount](packages/hoc.mount) - The high order component for mounting component
5755
- [@rcp/c.keepalive](packages/c.keepalive) - Keep react component view / store when switched view.
56+
- [@rcp/c.loadingwrapper](packages/c.loadingwrapper) - A component for easy create loading mask
5857
- [@rcp/hoc.i18n](packages/hoc.i18n) - React Component's high order component about internationalization
58+
- [@rcp/hoc.mount](packages/hoc.mount) - The high order component for mounting component
5959
- [@rcp/hoc.uncontrolled](packages/hoc.uncontrolled) - The high order component for creating uncontrolled component
6060
- [@rcp/use.i18n](packages/use.i18n) - A react hook for using i18n
6161
- [@rcp/util.createlogger](packages/util.createlogger) - Create namespace isomorphic logger

packages/c.keepalive/README.md

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,57 @@ yarn add @rcp/c.keepalive
1515

1616
## Usage
1717

18-
```javascript
19-
import cKeepalive from '@rcp/c.keepalive'
18+
```jsx
19+
import KeepAlive, { bindKeepAliveLifeCycle } from '@rcp/c.keepalive'
20+
import '@rcp/c.keepalive/style.less'
21+
22+
@bindKeepAliveLifeCycle
23+
class Content extends React.Component {
24+
// 新增的生命周期
25+
componentWillActive({newValue, oldValue}) {}
26+
componentDidActive({newValue, oldValue}) {}
27+
componentWillUnactive({newValue, oldValue}) {}
28+
componentDidUnactive({newValue, oldValue}) {}
29+
}
30+
31+
<KeepAlive uniqKey="/home" >
32+
<Content>Home</Content>
33+
<KeepAlive>
34+
// LifeCycle
35+
// componentWillActive => {newValue: '/home'}
36+
// componentDidActive => {newValue: '/home'}
37+
38+
// Components
39+
// <>
40+
// <Content>Home</Content>
41+
// </>
42+
43+
// Update
44+
<KeepAlive uniqKey="/detail" >
45+
<Content>Detail</Content>
46+
<KeepAlive>
47+
// LifeCycle
48+
// componentWillUnactive => {newValue: '/detail', oldValue: '/home'} (Home)
49+
// componentWillActive => {newValue: '/detail', oldValue: '/home'} (Detail)
50+
// componentDidUnactive => {newValue: '/detail', oldValue: '/home'} (Home)
51+
// componentDidActive => {newValue: '/detail', oldValue: '/home'} (Detail)
52+
53+
// Components
54+
// <>
55+
// <Content (display: none)>Home</Content>
56+
// <Content>Detail</Content>
57+
// </>
2058
```
2159

22-
## API
60+
## Props
61+
62+
### `uniqKey`
63+
64+
- **Type:** `string`
65+
66+
### `disabled`
67+
68+
- **Type:** `boolean`
2369

2470
## Related
2571

packages/c.keepalive/__tests__/spec.test.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ describe('KeepAlive', function() {
2121

2222
const KeepAliveLifeCycle = bindKeepAliveLifeCycle(
2323
class extends React.Component {
24+
componentWillMount() {}
2425
componentDidUnactive(input: InputType) {
2526
list.push('componentDidUnactive', input)
2627
}
@@ -92,10 +93,7 @@ describe('KeepAlive', function() {
9293
})
9394

9495
it('normal lifecycle', () => {
95-
// jest.spyOn(KeepAliveLifeCycle.prototype, 'componentWillActive')
96-
// jest.spyOn(KeepAliveLifeCycle.prototype, 'componentDidActive')
97-
// jest.spyOn(KeepAliveLifeCycle.prototype, 'componentWillUnactive')
98-
// jest.spyOn(KeepAliveLifeCycle.prototype, 'componentDidUnactive')
96+
jest.spyOn(KeepAliveLifeCycle.prototype, 'componentWillMount')
9997
const wrp = mount(<Page name={'bHome'} />)
10098
expect(list).toMatchInlineSnapshot(`
10199
Array [
@@ -238,5 +236,8 @@ Array [
238236
name: 'detail'
239237
})
240238
expect(list).toMatchInlineSnapshot(`Array []`)
239+
240+
// bHome & bDetail
241+
expect(KeepAliveLifeCycle.prototype.componentWillMount).toHaveBeenCalledTimes(2)
241242
})
242243
})

packages/c.keepalive/example/index.html

Lines changed: 0 additions & 10 deletions
This file was deleted.

packages/c.keepalive/example/index.tsx

Lines changed: 0 additions & 5 deletions
This file was deleted.

packages/c.loadingwrapper/README.md

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,47 @@ yarn add @rcp/c.loadingwrapper
1515

1616
## Usage
1717

18-
```javascript
19-
import cLoadingwrapper from '@rcp/c.loadingwrapper'
18+
```jsx
19+
import LoadingWrapper from '@rcp/c.loadingwrapper'
20+
import '@rcp/c.loadingwrapper/style.less'
21+
22+
<LoadingWrapper isLoading>
23+
<div>some content</div>
24+
</LoadingWrapper>
2025
```
2126

22-
## API
27+
## Props
28+
29+
### `className`
30+
31+
- **Type:** `string`
32+
- **Default:** `null`
33+
34+
### `isLoading`
35+
36+
- **Type:** `boolean`
37+
- **Default:** `false`
38+
39+
### `renderLoadingDelayMs`
40+
41+
渲染 Loading 延迟毫秒数,为了减少不必要的视觉跳跃
42+
43+
- **Type:** `number`
44+
- **Default:** `1000`
45+
46+
### `withDelayRenderFirstly`
47+
48+
是否首次的时候 Delay 渲染 Loading
49+
50+
- **Type:** `boolean`
51+
- **Default:** `false`
52+
53+
### `LoadingComponent`
2354

24-
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
55+
自定义 LoadingComponent
2556

26-
## Related
57+
- **Type:** `Component|Function|string`
58+
- **Default:** `null`
2759

2860
## Authors
2961

0 commit comments

Comments
 (0)