Skip to content

Commit f2ad51e

Browse files
committed
feat(hook): cleanupBuffer
1 parent 8dd0ef2 commit f2ad51e

File tree

1 file changed

+21
-1
lines changed
  • packages/app-backend-core/src

1 file changed

+21
-1
lines changed

Diff for: packages/app-backend-core/src/hook.ts

+21-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export function installHook (target, isIframe = false) {
6666
try {
6767
const hook = (window.parent as any).__VUE_DEVTOOLS_GLOBAL_HOOK__
6868
if (hook) {
69-
cb(hook)
69+
return cb(hook)
7070
} else {
7171
console.warn('[Vue Devtools] No hook in parent window')
7272
}
@@ -102,6 +102,10 @@ export function installHook (target, isIframe = false) {
102102
emit (event, ...args) {
103103
sendToParent(hook => hook.emit(event, ...args))
104104
},
105+
106+
cleanupBuffer (matchArg) {
107+
return sendToParent(hook => hook.cleanupBuffer(matchArg)) ?? false
108+
},
105109
}
106110
} else {
107111
hook = {
@@ -191,6 +195,22 @@ export function installHook (target, isIframe = false) {
191195
this._buffer.push([event, ...args])
192196
}
193197
},
198+
199+
/**
200+
* Remove buffered events with any argument that is equal to the given value.
201+
* @param matchArg Given value to match.
202+
*/
203+
cleanupBuffer (matchArg) {
204+
let wasBuffered = false
205+
this._buffer = this._buffer.filter(item => {
206+
if (item.some(arg => arg === matchArg)) {
207+
wasBuffered = true
208+
return false
209+
}
210+
return true
211+
})
212+
return wasBuffered
213+
},
194214
}
195215

196216
hook.once('init', Vue => {

0 commit comments

Comments
 (0)