Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f345e30

Browse files
author
febobo
committed
add ref and computed
1 parent 4a28abd commit f345e30

File tree

3 files changed

+55
-12
lines changed

3 files changed

+55
-12
lines changed

‎docs/.vuepress/config.js‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,19 @@ module.exports = {
4444
title: "前置知识",
4545
collapsable: false,
4646
children: [
47-
["es6/", "proxy"],
47+
["es6/", "Proxy"],
4848
["es6/dataStructure", "Set、Map、WeakSet、WeakMap"],
4949
["es6/typeScript", "typeScript语法"],
5050
["es6/spec", "spec语法"],
5151
],
5252
},
53+
{
54+
title: "全局Api",
55+
collapsable: false,
56+
children: [
57+
["global/", "global"],
58+
],
59+
},
5360
{
5461
title: "响应式系统",
5562
collapsable: false,
@@ -58,9 +65,13 @@ module.exports = {
5865
["reactivity/", "整体概览"],
5966
["reactivity/reactive", "reactive"],
6067
["reactivity/reactive.spec", "reactive.spec"],
68+
["reactivity/ref", "ref"],
69+
["reactivity/ref.spec", "ref.spec"],
6170
["reactivity/baseHandlers", "baseHandlers"],
6271
["reactivity/effect", "effect"],
6372
["reactivity/effect.spec", "effect.spec"],
73+
["reactivity/computed", "computed"],
74+
["reactivity/computed.spec", "computed.spec"],
6475
],
6576
},
6677
{

‎docs/reactivity/index.md‎

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
### reactivie 整体概览
22

3+
先看一眼官方对 `reactivie` 的定义
34

5+
> This package is inlined into Global & Browser ESM builds of user-facing renderers (e.g. @vue/runtime-dom), but also published as a package that can be used standalone. The standalone build should not be used alongside a pre-bundled build of a user-facing renderer, as they will have different internal storage for reactivity connections. A user-facing renderer should re-export all APIs from this package.
46
5-
前面又说到过,开始之前我们要理清楚各个文件之间的关系及作用,那么在我们即将要开始进入`reactive`之前,我们也来理一下整个`reactive`的文件结构
7+
大概意思是说这个包是内嵌到vue的渲染器中(@vue/runtime-dom),但是它也可以单独发布或者被第三方引用,需要注意的是如果你是提供给第三方渲染器使用,其内部可能已经实现了响应机制,可能出现兼容问题
68

7-
```
9+
**为了后面阅读大家更容易阅读,开始之前我们需要理解各个文件之间的关系及用途**
10+
11+
下方为整个`reactive`的文件结构
12+
13+
```js
814
.
915
├── LICENSE
1016
├── README.md
@@ -24,12 +30,38 @@
2430
├── index.js
2531
├── package.json
2632
└── src
27-
├── baseHandlers.ts
28-
├── collectionHandlers.ts
29-
├── computed.ts
30-
├── effect.ts
33+
├── baseHandlers.ts// 基本类型的处理器
34+
├── collectionHandlers.ts// Set Map WeakSet WeckMap的处理器
35+
├── computed.ts// 计算属性,同Vue2
36+
├── effect.ts// reactive 核心,处理依赖收集,依赖更新
3137
├── index.ts
32-
├── operations.ts
33-
├── reactive.ts
34-
└── ref.ts
35-
```
38+
├── operations.ts // 定义依赖收集,依赖更新的类型
39+
├── reactive.ts // reactive 入口,内部主要以Proxy实现
40+
└── ref.ts // reactive 的变种方法,Proxy处理不了值类型的响应,Ref来处理
41+
```
42+
43+
还为大家提供了整个 `reactive` 的流程图
44+
45+
**整体流程**
46+
47+
<p>
48+
<img src="https://static.vue-js.com/c2344a60-cd86-11ea-ae44-f5d67be454e7.png" width="80%">
49+
</p>
50+
51+
### 建议顺序阅读
52+
53+
* [/reactivity/reactive](reactive)
54+
* [/reactivity/baseHandlers](baseHandlers)
55+
* [/reactivity/effect](effect)
56+
* [/reactivity/ref](ref)
57+
* [/reactivity/computed](computed)
58+
59+
<!-- **reactive 流程**
60+
<p>
61+
<img src="https://static.vue-js.com/0969ba10-cd90-11ea-ae44-f5d67be454e7.png" width="50%">
62+
</p>
63+
64+
**ref 流程**
65+
<p>
66+
<img src="https://static.vue-js.com/244c65c0-cd91-11ea-ae44-f5d67be454e7.png" width="100%">
67+
</p> -->

‎docs/reactivity/reactive.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Vue3中响应数据核心是 `reactive` , `reactive` 中的实现是由 `proxy
1616
export function reactive<T extends object>(target: T): UnwrapNestedRefs<T>
1717
export function reactive(target: object) {
1818
// if trying to observe a readonly proxy, return the readonly version.
19-
// 如果传入了目标对象且目标对象为只读属性,则直接返回目标对象
19+
// 如果目标对象是一个只读的响应数据,则直接返回目标对象
2020
if (target && (target as Target).__v_isReadonly) {
2121
return target
2222
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /