diff options
author | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2022-01-18 10:09:14 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-18 10:09:14 +0100 |
commit | 59480d677a689f808b1e80b9556d481afc03498b (patch) | |
tree | 89fff4e0144e3f4d8e60e0a75964e4e8c34c8e9c | |
parent | 480e5d77e2dcefd6bc4f95a053bb545d9916eb72 (diff) | |
parent | 5098597cb14df8a0be9249fcabbdf5b6d126cd85 (diff) | |
download | svg.js-59480d677a689f808b1e80b9556d481afc03498b.tar.gz svg.js-59480d677a689f808b1e80b9556d481afc03498b.zip |
Merge pull request #1249 from Mscht/1248-event-target-off-param-options
Add parameter "options" to EventTarget.off()
-rw-r--r-- | spec/spec/types/EventTarget.js | 11 | ||||
-rw-r--r-- | src/types/EventTarget.js | 4 | ||||
-rw-r--r-- | svg.js.d.ts | 6 |
3 files changed, 16 insertions, 5 deletions
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
}
|