Fix hook effect schedule - #870
Merged
Merged
Conversation
|
|
Collaborator
|
OK,我看下 |
yuanyan
reviewed
Jan 15, 2019
| // using _penddingContext to pass new context | ||
| prevRootInstance._internal._penddingContext = parentContext; | ||
| } | ||
| prevRootInstance.setState({ |
Collaborator
There was a problem hiding this comment.
通过 setState 来触发更新是一个不错的方式,但 rootInstance 暴露的接口是可以更语义化些,比如 prevRootInstance.update(element)
yongningfu
commented
Jan 15, 2019
| let defaultContext = parentContext || {}; | ||
| let rootInstance = renderedComponent.mountComponent(container, null, defaultContext); | ||
| this.set(container, rootInstance); | ||
| rootInstance.setState({ |
Collaborator
Author
There was a problem hiding this comment.
这里这样改的话,test case应该过不了吧? A 正在更新, render(B, container) 即发生了B的mount, B应该延迟mount,基于此,当时这里render设计的模型是 render的组件无论mount还是update 都统一走更新的逻辑,这样的话,都能被更新模型调度到,更新模型会检测到当前有A组正在更新, 以此来延迟B mount
yuanyan
approved these changes
Jan 17, 2019
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
主要解决三个问题:
这个应该是js写法中 比较常见的bug, 先声明 const setImmediate, 然后使用 typeof setImmediate, 这个setImmediate应该是我们声明的那个setImmediate,所以typeof setImmediate === 'undefined' 一定为true
渲染中 发生更新如何解决?
setState应该可以在任何的生命周期方法中调用
实现中有几个需要注意的点:
rootInstance.setState({element,});
因为setState可能会延迟渲染,先注册到container中,如果后面还有同一个container的render ,可以实现
render的batch update,有/tests/render.js中有对应的case
hook effect的调度
effect应该是下一次渲染前 会执行, 如何去理解下一次渲染前??
比如 A.setState --> A 更新中发生了 B, C需要调度更新,B, C再更新的时候,又调度了 D E F更新
这里实现的effect刷新的模型是 A -> flush effect -> B C -> flush effect -> D E F -> flush effect
实现
官方的effect的case 基本已经覆盖了
可以在生命周期中执行setState
rax在hook的使用下,更新也是同步的
本来想分几个pr的,但是hook存在,调度和hook耦合,不好分开pr