diff --git a/.changeset/lemon-berries-change.md b/.changeset/lemon-berries-change.md new file mode 100644 index 000000000..2748fe225 --- /dev/null +++ b/.changeset/lemon-berries-change.md @@ -0,0 +1,5 @@ +--- +"@tiptap/core": patch +--- + +feat: add `once` to EventEmitters diff --git a/packages/core/src/EventEmitter.ts b/packages/core/src/EventEmitter.ts index 0aa0fe880..104ecf633 100644 --- a/packages/core/src/EventEmitter.ts +++ b/packages/core/src/EventEmitter.ts @@ -46,6 +46,15 @@ export class EventEmitter> { return this } + public once>(event: EventName, fn: CallbackFunction): this { + const onceFn = (...args: CallbackType) => { + this.off(event, onceFn) + fn.apply(this, args) + } + + return this.on(event, onceFn) + } + public removeAllListeners(): void { this.callbacks = {} }