docs(ref): 更新 ref 实现的注释文档
- 为 RefImpl 构造函数添加原始数据注释 - 为 value setter 方法添加详细的参数和逻辑说明 - 为 newValue 和 _rawValue 的比较逻辑添加注释 - 为 value setter 中的数据更新流程添加步骤注释 - 更新 triggerRefValue 函数的注释描述
This commit is contained in:
@@ -25,6 +25,7 @@ class RefImpl<T> {
|
|||||||
value: T,
|
value: T,
|
||||||
public readonly __v_isShallow: boolean
|
public readonly __v_isShallow: boolean
|
||||||
) {
|
) {
|
||||||
|
//原始数据
|
||||||
this._rawValue = value
|
this._rawValue = value
|
||||||
this._value = __v_isShallow ? value : toReactive(value)
|
this._value = __v_isShallow ? value : toReactive(value)
|
||||||
}
|
}
|
||||||
@@ -32,15 +33,24 @@ class RefImpl<T> {
|
|||||||
trackRefValue(this)
|
trackRefValue(this)
|
||||||
return this._value
|
return this._value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* newValue 新数据
|
||||||
|
* this._rawValue为旧数据(原始数据)
|
||||||
|
* 对比两个数据是否发生改变
|
||||||
|
*/
|
||||||
set value(newValue) {
|
set value(newValue) {
|
||||||
if (hasChanged(newValue, this._rawValue)) {
|
if (hasChanged(newValue, this._rawValue)) {
|
||||||
|
//更新原始数据
|
||||||
this._rawValue = newValue
|
this._rawValue = newValue
|
||||||
|
//更新 .value的值
|
||||||
this._value = toReactive(newValue)
|
this._value = toReactive(newValue)
|
||||||
|
//触发依赖
|
||||||
triggerRefValue(this)
|
triggerRefValue(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//触发依赖
|
//为ref的value进行触发依赖工作
|
||||||
export function triggerRefValue(ref) {
|
export function triggerRefValue(ref) {
|
||||||
if (ref.dep) {
|
if (ref.dep) {
|
||||||
triggerEffects(ref.dep)
|
triggerEffects(ref.dep)
|
||||||
|
|||||||
Reference in New Issue
Block a user