Skip to content

feat: batchDestory #53

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

Merged
merged 17 commits into from
Mar 6, 2025
Merged

feat: batchDestory #53

merged 17 commits into from
Mar 6, 2025

Conversation

WeilinerL
Copy link
Contributor

@WeilinerL WeilinerL commented Dec 6, 2024

问题背景

非Vue上下文调用(this.$createXxx),无法拿到当前组件的实例,从而在路由切换的时候不会关闭弹窗

解决方案

提供的batchDestroy方法统一销毁由非Vue上下文调用(this.$createXxx)产生的实例,例如我们可以在路由切换的时候进行统一销毁:

使用方法

在项目的main.ts中引入createAPI,并监听路由变化:

import CreateAPI from 'vue-create-api'

router.afterEach(() => {
  CreateAPI.batchDestroy()
})

@WeilinerL WeilinerL changed the title 提供插件能力 feat: 提供插件能力 Dec 6, 2024
@WeilinerL
Copy link
Contributor Author

@dolymood @CommanderXL 老板们有空的时候帮忙看下这个feature

src/index.js Outdated
@@ -32,6 +52,7 @@ function processComponentName(Component, options) {
}

export default {
use,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感觉引入插件的机制有点冗余,本身这个功能就是 createApi 自身提供的,这里对外暴露一个类似于 batchDestroy 的方法感觉就行了。

src/creator.js Outdated
if (isInVueInstance) {
ownerInstance.$on(eventBeforeDestroy, beforeDestroy)
} else if (firstCreation) {
ctx.on(ctx.Event.InstanceDestroy, component.remove)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里也不用事件去驱动了,用一个数组去收集所有的实例,如果通过 batchDestroy 的方法来清空数组就行了。

@WeilinerL WeilinerL changed the title feat: 提供插件能力 feat: batchDestory Jan 23, 2025
src/cache.js Outdated

export function add(component) {
let ins
let alreadyIn = false
Copy link
Contributor

@CommanderXL CommanderXL Feb 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感觉不需要维护这个 alreadyIn 吧?如果判断有,直接从这个函数 return 出去就行了

@CommanderXL CommanderXL merged commit f5d6cc5 into cube-ui:master Mar 6, 2025
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.

2 participants