-
Notifications
You must be signed in to change notification settings - Fork 918
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
《Vue.js设计与实现》问题记录 #340
Comments
11.2 判断是否需要进行 DOM 移动操作 |
5.4 合理的触发响应 const observed = reactive(new Array(3))
effect(() => {
console.log(observed.length)
})
// 下面用例不会影响数组长度变化,不应该触发副作用函数重新执行
observed.x = 'x' // 非索引属性
observed[-1] = 'x' // 负索引
observed[1] = 1 // 已存在索引 function createSetter(shallow = false) {
return function set(
target: object,
key: string | symbol,
value: unknown,
receiver: object
): boolean {
let oldValue = (target as any)[key]
// 省略代码...
const hadKey =
// 新增判断
isArray(target) && isIntegerKey(key)
? Number(key) < target.length
: hasOwn(target, key)
const result = Reflect.set(target, key, value, receiver)
// don't trigger if target is something up in the prototype chain of original
if (target === toRaw(receiver)) {
if (!hadKey) {
trigger(target, TriggerOpTypes.ADD, key, value)
} else if (hasChanged(value, oldValue)) {
trigger(target, TriggerOpTypes.SET, key, value, oldValue)
}
}
return result
}
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
7.3 自定义渲染器
这里应该是 text
The text was updated successfully, but these errors were encountered: