mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-11-27 14:59:27 +08:00
feat: add once
to EventEmitters (#5818)
This commit is contained in:
parent
62c6dddf80
commit
53673fbfe0
5
.changeset/lemon-berries-change.md
Normal file
5
.changeset/lemon-berries-change.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@tiptap/core": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
feat: add `once` to EventEmitters
|
@ -46,6 +46,15 @@ export class EventEmitter<T extends Record<string, any>> {
|
|||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public once<EventName extends StringKeyOf<T>>(event: EventName, fn: CallbackFunction<T, EventName>): this {
|
||||||
|
const onceFn = (...args: CallbackType<T, EventName>) => {
|
||||||
|
this.off(event, onceFn)
|
||||||
|
fn.apply(this, args)
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.on(event, onceFn)
|
||||||
|
}
|
||||||
|
|
||||||
public removeAllListeners(): void {
|
public removeAllListeners(): void {
|
||||||
this.callbacks = {}
|
this.callbacks = {}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user