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

关于小程序 setData #14

Open
hz9527 opened this issue Nov 14, 2018 · 1 comment
Open

关于小程序 setData #14

hz9527 opened this issue Nov 14, 2018 · 1 comment

Comments

@hz9527
Copy link

hz9527 commented Nov 14, 2018

你好。我先描述下背景吧。
我还没正经开发过小程序,最近在做相关工作(封装一个小程序框架)
比如有这样一个业务场景,一个页面里有一个组件,页面监听了某个子组件的事件,在回调里setData了,而这个子组件因为监听了生命周期或者UI事件也setData了,并 trigger 了页面监听的这个事件。我想了解一下这个过程到底是怎样的?

  1. 是否会引发两次渲染?
  2. trigger 是同步还是异步的?理论上同步的可能性比较大

不太清楚 setData 到 webview 那边的通信时间和内部放置的队列情况,不过应该是宏队列,但是浏览器本身也对宏队列做了优化(比如连续在 setTimeout 0 操作 dom,不论是重绘还是重排,浏览器也会有自己的一套 isNeedRender 的算法优化)

@godbasin
Copy link
Owner

  1. 会引发两次树节点计算,但通讯有优化,只会有一次渲染。
  2. triggerEvent 完全是一个同步调用。

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