Skip to content

Commit

Permalink
feat(hook): cleanupBuffer
Browse files Browse the repository at this point in the history
  • Loading branch information
Akryum committed Oct 3, 2022
1 parent 8dd0ef2 commit f2ad51e
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion packages/app-backend-core/src/hook.ts
Expand Up @@ -66,7 +66,7 @@ export function installHook (target, isIframe = false) {
try {
const hook = (window.parent as any).__VUE_DEVTOOLS_GLOBAL_HOOK__
if (hook) {
cb(hook)
return cb(hook)
} else {
console.warn('[Vue Devtools] No hook in parent window')
}
Expand Down Expand Up @@ -102,6 +102,10 @@ export function installHook (target, isIframe = false) {
emit (event, ...args) {
sendToParent(hook => hook.emit(event, ...args))
},

cleanupBuffer (matchArg) {
return sendToParent(hook => hook.cleanupBuffer(matchArg)) ?? false
},
}
} else {
hook = {
Expand Down Expand Up @@ -191,6 +195,22 @@ export function installHook (target, isIframe = false) {
this._buffer.push([event, ...args])
}
},

/**
* Remove buffered events with any argument that is equal to the given value.
* @param matchArg Given value to match.
*/
cleanupBuffer (matchArg) {
let wasBuffered = false
this._buffer = this._buffer.filter(item => {
if (item.some(arg => arg === matchArg)) {

This comment has been minimized.

Copy link
@posva

posva Oct 3, 2022

Member

you can also use item.includes()

wasBuffered = true
return false
}
return true
})
return wasBuffered
},
}

hook.once('init', Vue => {
Expand Down

0 comments on commit f2ad51e

Please sign in to comment.