Skip to content

Commit

Permalink
Merge pull request #1249 from Mscht/1248-event-target-off-param-options
Browse files Browse the repository at this point in the history
Add parameter "options" to EventTarget.off()
  • Loading branch information
Fuzzyma authored Jan 18, 2022
2 parents 480e5d7 + 5098597 commit 59480d6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
11 changes: 11 additions & 0 deletions spec/spec/types/EventTarget.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/types/EventTarget.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
6 changes: 3 additions & 3 deletions svg.js.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 59480d6

Please sign in to comment.