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

data.hook 中的 create hook是哪来的 #103

Closed
a1mersnow opened this issue Aug 31, 2020 · 2 comments
Closed

data.hook 中的 create hook是哪来的 #103

a1mersnow opened this issue Aug 31, 2020 · 2 comments

Comments

@a1mersnow
Copy link

function invokeCreateHooks (vnode, insertedVnodeQueue) {
    for (let i = 0; i < cbs.create.length; ++i) {
      cbs.create[i](emptyNode, vnode)
    }
    i = vnode.data.hook // Reuse variable
    if (isDef(i)) {
      if (isDef(i.create)) i.create(emptyNode, vnode)
      if (isDef(i.insert)) insertedVnodeQueue.push(vnode)
    }
  }

core/vdom/patch 里有这个方法

我找了好久都没找到 create hook的来源,我去我的一个项目里加了断点,测了几个地方发现这个地方根本没有执行,所以i.create(emptyNode, vnode)这一句到底是什么作用?

@a1mersnow
Copy link
Author

单元测试倒是有用这个create hook 难道只是测试用……

@ominus3
Copy link

ominus3 commented Jan 21, 2021

vue 提供的 vnode 创建的过程中的一些钩子函数,下面这个我试了一下是会走到 i.create(emptyNode, vnode)

  render(h) {
    return h('div', {
      hook: {
        create() {
          console.log('vnode create')
        }
      },
    }, 123)
  }

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