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

dep和effect之间的对应关系 #20

Closed
wd2010 opened this issue Jun 9, 2021 · 2 comments
Closed

dep和effect之间的对应关系 #20

wd2010 opened this issue Jun 9, 2021 · 2 comments

Comments

@wd2010
Copy link

wd2010 commented Jun 9, 2021

崔老师好,最近在研究reactivity模块,对应dep和effect之间知道有如下的关系,但当嵌套依赖复杂点,就搞不清楚了,请问你是怎么理解这一块的?

// effect 和dep之间的对应关系
targetMap: {
    target1: {
        key1: [effect1, effect2, ...],
        key2: [effect1, effect2, ...],
        key3: [effect1, effect2, ...],
        ...
    } 
}
effect.deps = [
    [effect1, effect2, ...],
    [effect1, effect2, ...],
    [effect1, effect2, ...],
    ...
]

但当加入computed,ref后,感觉有点绕不清了,比如:

const count = ref(0) 
const plusOne = computed(() => { 
  return count.value + 1 
}) 
effect(() => { 
  // plusOne.value 和 count.value顺序不一样,输出结果不一样
  // console.log( plusOne.value + count.value) 
  console.log(count.value + plusOne.value) 
}) 
function plus() { 
  count.value++ 
} 
plus()

再比如:

const count = ref(0) 
const plusOne = computed(() => { 
  return count.value + 1 
}) 
const plusTwo = computed(() => { 
  return plusOne.value + 1 
}) 
console.log(plusTwo.value)
@chengazhen
Copy link

全局Dep => 精确到对象的 Dep => 精确到 key的 dep

去看下 尤雨溪的视频就明白了

@cuixiaorui
Copy link
Owner

可以关注一波 #23

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

3 participants