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

refactor: 重构选择事件监听hook #365

Merged
merged 1 commit into from
May 7, 2024

Conversation

wuchenguang1998
Copy link
Member

修复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,提供给有需要的组件。
最终效果:
选择事件的监听大幅减少,控制台警告消除。

@Qiu-Jun
Copy link
Collaborator

Qiu-Jun commented May 5, 2024

这个hooks是vue2版本时的mixin, 之前我试过把他放到home处理,但是好像忘记出了啥问题来着。我节后看看,没问题再合并

@nihaojob nihaojob merged commit 0aa242e into ikuaitu:main May 7, 2024
1 check passed
@nihaojob
Copy link
Member

nihaojob commented May 7, 2024

@wuchenguang1998 @Qiu-Jun 感谢两位,代码已经合并到主分支。

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

Successfully merging this pull request may close these issues.

3 participants