fix(extension): 【dynamic-group】componentWillUnmount移除事件监听,解决折叠再展开的子元素移动错乱问题 #1919
+107
−85
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.
fix #1912
问题发生的原因
下面视频展示的关系为:dynamicGroupA嵌套dynamicGroupB,dynamicGroupB嵌套普通Node
由于dynamicGroupA嵌套dynamicGroupB,在dynamicGroupA进行折叠时,会触发dynamicGroupB的隐藏,从而触发dynamicGroupB的
componentWillUnmount()
销毁,但是如下面视频所示,dynamicGroupB的componentDidMount()
注册了很多事件:但是忘记执行对应的事件移除,因此导致每一次折叠=>展开的时候,都会重复注册一次事件,因此导致下面视频所展示触发多次
moveNodes
,也就是dynamicGroupB移动1px,会触发多次它的children的1px
移动,从而造成移动错乱问题on-off.mp4
解决方法
将componentDidMount注册的监听事件方法抽离出来,为后面解除事件监听做准备
交互逻辑无变化,只是将注册方法抽离为
this.xxxx
方法,放在外部componentWillUnmount移除监听