docs(ref): 更新 ref 实现的注释文档

- 为 RefImpl 构造函数添加原始数据注释
- 为 value setter 方法添加详细的参数和逻辑说明
- 为 newValue 和 _rawValue 的比较逻辑添加注释
- 为 value setter 中的数据更新流程添加步骤注释
- 更新 triggerRefValue 函数的注释描述
This commit is contained in:
dj
2026-02-05 23:53:27 +08:00
parent 2ed86a03b5
commit c0853b353d

View File

@@ -25,6 +25,7 @@ class RefImpl<T> {
value: T,
public readonly __v_isShallow: boolean
) {
//原始数据
this._rawValue = value
this._value = __v_isShallow ? value : toReactive(value)
}
@@ -32,15 +33,24 @@ class RefImpl<T> {
trackRefValue(this)
return this._value
}
/**
* newValue 新数据
* this._rawValue为旧数据(原始数据)
* 对比两个数据是否发生改变
*/
set value(newValue) {
if (hasChanged(newValue, this._rawValue)) {
//更新原始数据
this._rawValue = newValue
//更新 .value的值
this._value = toReactive(newValue)
//触发依赖
triggerRefValue(this)
}
}
}
//触发依赖
//为ref的value进行触发依赖工作
export function triggerRefValue(ref) {
if (ref.dep) {
triggerEffects(ref.dep)