Skip to content
This repository has been archived by the owner on Nov 17, 2022. It is now read-only.

docs: store #504

Merged
merged 9 commits into from
Sep 26, 2022
Merged

docs: store #504

merged 9 commits into from
Sep 26, 2022

Conversation

luhc228
Copy link
Member

@luhc228 luhc228 commented Sep 5, 2022

顺带修复了 diff 语法不高亮的问题(是配置的主题引起的)

@vercel
Copy link

vercel bot commented Sep 5, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
ice-v3 ✅ Ready (Inspect) Visit Preview Sep 19, 2022 at 10:07AM (UTC)

@codecov-commenter
Copy link

codecov-commenter commented Sep 5, 2022

Codecov Report

Base: 82.12% // Head: 82.12% // No change to project coverage 👍

Coverage data is based on head (0fdb385) compared to base (5d10f02).
Patch has no changes to coverable lines.

Additional details and impacted files
@@              Coverage Diff              @@
##           release-next     #504   +/-   ##
=============================================
  Coverage         82.12%   82.12%           
=============================================
  Files                90       90           
  Lines              7669     7669           
  Branches            971      971           
=============================================
  Hits               6298     6298           
  Misses             1364     1364           
  Partials              7        7           

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.


export default store.withModel('todos')(TodoList);
// 绑定多个 model
// export default withModel('user')(withModel('todos')(TodoList));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是否默认推荐 decorator 的形式包装 component:

  1. ts 里需要在 tsconfig 里添加 compilerOptions 的
    "experimentalDecorators": true 才可启用
  2. ts 不支持为 function 添加 decoration
  3. 需要在项目中依赖 tslib

个人建议:

  1. withModel 仅开放给 Class Component, 默认用 decorators
  2. 对于 Function Component 还是推荐用 hooks 的方式

@wssgcg1213
Copy link
Collaborator

冲突了

order: 2
---

import Tabs from '@theme/Tabs';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以提供个示例组件

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

封装了一个组件后,样式就出不来了


## 全局状态

推荐在不同页面组件中使用的状态存放在全局状态中,比如主题、国际化语言、用户信息等。
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

推荐在不同页面组件中使用的状态存放在全局状态中 -> 推荐在不同页面组件中共享的状态存放在全局状态中

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


```diff
import { useEffect } from 'react';
import store from '@/store';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

少了 + 号

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

// const data = (await fetch('your-url')).json();
return {
initialStates: {
user: {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

models/user.ts 和 models/counter.ts 内容怎么写有没有限制,这个键值是跟文件名对应吗

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已补充

#### reducers

```ts
reducers: { [string]: (prevState, payload) => any }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以用标准类型的写法 说明下这个是 reducers 的类型

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

reducers: { [string]: (prevState, payload) => any }
```

一个改变该模型状态的函数集合。这些方法以模型的上一次 prevState 和一个 payload 作为入参,在方法中使用可变的方式来更新状态。这些方法应该是仅依赖于 prevState 和 payload 参数来计算下一个 nextState 的纯函数。对于有副作用的函数,请使用 effects。
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prevState / payload / nextState / effects 术语要不要统一说明下是什么意思,effects 下面有说明的可以直接链接过去

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

#### effects

```ts
effects: (dispatch) => ({ [string]: (payload, rootState) => void })
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上 type Effects = xxx

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

effects: (dispatch) => ({ [string]: (payload, rootState) => void })
```

一个可以处理该模型副作用的函数集合。这些方法以 payload 和 rootState 作为入参,适用于进行异步调用、模型联动等场景。
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rootState 的说明

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

</Tabs>


### Model 中使用 immer 更改 State
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

标题倾向于:不可变状态,然后说明推荐状态不可变,并且可以通过开启 immer 的方式来将简化不可变操作

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

})
```

### 获取 effects 的 loading/error 状态
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

获取内置状态:加载状态、错误状态

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@luhc228 luhc228 merged commit 7c85915 into release-next Sep 26, 2022
@luhc228 luhc228 deleted the docs/store branch September 26, 2022 08:14
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants