From: Mario Schlicht Date: Tue, 18 Jan 2022 07:01:58 +0000 (+0100) Subject: Add parameter "options" to EventTarget.off() X-Git-Tag: 3.1.2~1^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=5098597cb14df8a0be9249fcabbdf5b6d126cd85;p=svg.js.git Add parameter "options" to EventTarget.off() - additional: Typescript-Interfaces for off() functions updated --- diff --git a/spec/spec/types/EventTarget.js b/spec/spec/types/EventTarget.js index e27a71c..82e5a94 100644 --- a/spec/spec/types/EventTarget.js +++ b/spec/spec/types/EventTarget.js @@ -101,6 +101,17 @@ describe('EventTarget.js', () => { target.dispatch('event') expect(spy.calls.count()).toBe(1) }) + + it('removes an event binding with options from the target', () => { + const target = new EventTarget() + const spy = createSpy() + target.on('event', spy, undefined, { capture: true }) + target.dispatch('event') + expect(spy.calls.count()).toBe(1) + target.off('event', spy, { capture: true }) + target.dispatch('event') + expect(spy.calls.count()).toBe(1) + }) }) describe('on()', () => { diff --git a/src/types/EventTarget.js b/src/types/EventTarget.js index 6889605..58f5d5c 100644 --- a/src/types/EventTarget.js +++ b/src/types/EventTarget.js @@ -39,8 +39,8 @@ export default class EventTarget extends Base { } // Unbind event from listener - off (event, listener) { - off(this, event, listener) + off (event, listener, options) { + off(this, event, listener, options) return this } diff --git a/svg.js.d.ts b/svg.js.d.ts index 0560a62..baef3b9 100644 --- a/svg.js.d.ts +++ b/svg.js.d.ts @@ -27,8 +27,8 @@ declare module "@svgdotjs/svg.js" { function on(el: Node | Window, events: string, cb: EventListener, binbind?: any, options?: AddEventListenerOptions): void; function on(el: Node | Window, events: Event[], cb: EventListener, binbind?: any, options?: AddEventListenerOptions): void; - function off(el: Node | Window, events?: string, cb?: EventListener | number): void; - function off(el: Node | Window, events?: Event[], cb?: EventListener | number): void; + function off(el: Node | Window, events?: string, cb?: EventListener | number, options?: AddEventListenerOptions): void; + function off(el: Node | Window, events?: Event[], cb?: EventListener | number, options?: AddEventListenerOptions): void; function dispatch(node: Node | Window, event: Event, data?: object, options?: object): Event @@ -579,7 +579,7 @@ declare module "@svgdotjs/svg.js" { getEventTarget(): this | Node on(events: string | Event[], cb: EventListener, binbind?: any, options?: AddEventListenerOptions): this; - off(events?: string | Event[], cb?: EventListener | number): this; + off(events?: string | Event[], cb?: EventListener | number, options?: AddEventListenerOptions): this; removeEventListener(): void }