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.
修复issue#364
出现问题的原因是:
emitter监听了太多事件,超过了默认最大监听数。排查发现,多个组件都调用了src\hooks\select.ts的自定义hook,这个hook在onMounted时监听了3个画布元素的选择事件。导致多个组件调用这hook时,这3个事件被反复监听。通过console.log(canvasEditor.listenerCount(SelectEvent.ONE));查看,发现selectOne监听了近30次,其中多数是来源于这个自定义hook。
本次提交的改动:
将src\hooks\select.ts主要监听逻辑抽取成新的hook(useSelectListen),在src\views\home\index.vue调用一次,并将mixinState暴露。原来的src\hooks\select.ts通过inject获取mixinState,提供给有需要的组件。
最终效果:
选择事件的监听大幅减少,控制台警告消除。