Skip to content
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

Open
jizai1125 opened this issue Dec 28, 2022 · 7 comments
Open

《Vue.js设计与实现》问题记录 #340

jizai1125 opened this issue Dec 28, 2022 · 7 comments

Comments

@jizai1125
Copy link

jizai1125 commented Dec 28, 2022

7.3 自定义渲染器
这里应该是 text

image

@jizai1125 jizai1125 changed the title 7.3 自定义渲染器 - 代码示例错误 7.3 自定义渲染器 - 代码错别字 Jan 10, 2023
@jizai1125 jizai1125 changed the title 7.3 自定义渲染器 - 代码错别字 错别字 May 11, 2023
@jizai1125
Copy link
Author

8.4 class 的处理
image

@jizai1125 jizai1125 changed the title 错别字 《Vue.js设计与实现》错别字记录 Jun 8, 2023
@jizai1125 jizai1125 changed the title 《Vue.js设计与实现》错别字记录 《Vue.js设计与实现》问题记录 Jun 8, 2023
@jizai1125
Copy link
Author

5.8.3 避免污染原始数据
文字错误,这里应该是存在
image

@jizai1125
Copy link
Author

10.1 双端 比较的原理
这里应该是大于
image

@jizai1125
Copy link
Author

jizai1125 commented Jun 8, 2023

11.2 判断是否需要进行 DOM 移动操作
源码里面代表新增节点的初始值是 0,跟赋值为 -1 有什么区别?
image

@jizai1125
Copy link
Author

5.4 合理的触发响应
不知道理解的对不对?
看源码时多了一种数组场景下的判断:不影响数组长度变化但是会触发副作用函数重新执行

const observed = reactive(new Array(3))
effect(() => {
  console.log(observed.length)
})
// 下面用例不会影响数组长度变化,不应该触发副作用函数重新执行
observed.x = 'x' // 非索引属性
observed[-1] = 'x'  // 负索引
observed[1] = 1  // 已存在索引

PR: fix(reactivity): add existing index or non-integer prop on Array should not trigger length dependency

源码

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
  }
}

@jizai1125
Copy link
Author

14.4 总结
文字错误,选项才对
image

@jizai1125
Copy link
Author

17.2.1 带有 v-if 指令的节点
这里 key 不应该被包在对象里面吧
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
@jizai1125 and others