-
Notifications
You must be signed in to change notification settings - Fork 39
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
Conversation
@dolymood @CommanderXL 老板们有空的时候帮忙看下这个feature |
src/index.js
Outdated
@@ -32,6 +52,7 @@ function processComponentName(Component, options) { | |||
} | |||
|
|||
export default { | |||
use, |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里也不用事件去驱动了,用一个数组去收集所有的实例,如果通过 batchDestroy 的方法来清空数组就行了。
src/cache.js
Outdated
|
||
export function add(component) { | ||
let ins | ||
let alreadyIn = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
感觉不需要维护这个 alreadyIn 吧?如果判断有,直接从这个函数 return 出去就行了
问题背景
非Vue上下文调用(this.$createXxx),无法拿到当前组件的实例,从而在路由切换的时候不会关闭弹窗
解决方案
提供的
batchDestroy
方法统一销毁由非Vue上下文调用(this.$createXxx)产生的实例,例如我们可以在路由切换的时候进行统一销毁:使用方法
在项目的main.ts中引入createAPI,并监听路由变化: