Browse Source

Merge pull request #1249 from Mscht/1248-event-target-off-param-options

Add parameter "options" to EventTarget.off()
tags/3.1.2
Ulrich-Matthias Schäfer 2 years ago
parent
commit
59480d677a
No account linked to committer's email address
3 changed files with 16 additions and 5 deletions
  1. 11
    0
      spec/spec/types/EventTarget.js
  2. 2
    2
      src/types/EventTarget.js
  3. 3
    3
      svg.js.d.ts

+ 11
- 0
spec/spec/types/EventTarget.js View File

target.dispatch('event') target.dispatch('event')
expect(spy.calls.count()).toBe(1) 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()', () => { describe('on()', () => {

+ 2
- 2
src/types/EventTarget.js View File

} }


// Unbind event from listener // Unbind event from listener
off (event, listener) {
off(this, event, listener)
off (event, listener, options) {
off(this, event, listener, options)
return this return this
} }



+ 3
- 3
svg.js.d.ts View File

function on(el: Node | Window, events: string, cb: EventListener, binbind?: any, options?: AddEventListenerOptions): void; 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 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 function dispatch(node: Node | Window, event: Event, data?: object, options?: object): Event
getEventTarget(): this | Node getEventTarget(): this | Node
on(events: string | Event[], cb: EventListener, binbind?: any, options?: AddEventListenerOptions): this; 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 removeEventListener(): void
} }

Loading…
Cancel
Save