Skip to content

Releases: fregante/delegate-it

v6.2.1

28 Oct 07:50
Compare
Choose a tag to compare

v6.2.0...v6.2.1

v6.2.0

20 Aug 10:06
Compare
Choose a tag to compare

v6.1.0...v6.2.0

v6.1.0

18 Mar 14:52
Compare
Choose a tag to compare

v6.0.1...v6.1.0

v6.0.1

25 Apr 15:16
Compare
Choose a tag to compare

v6.0.0...v6.0.1

v6.0.0

25 Apr 12:03
Compare
Choose a tag to compare

Breaking changes

Move base to options (#46) 247ac87

- delegate(document, 'a', 'click', alert)
+ delegate('a', 'click', alert)
- delegate(myBaseElement, 'a', 'click', alert)
+ delegate('a', 'click', alert, {base: myBaseElement})

Drop support for boolean-only options (#44) 7b3dc8a

- delegate(document, 'a', 'click', alert, true)
+ delegate('a', 'click', alert, {capture: true})

Drop support for selectors and arrays as base (#45) 5b5138b

- delegate('.my-base-element', 'a', 'click', alert)
- delegate(document.querySelectorAll('.my-base-element'), 'a', 'click', alert)

New

Add promised oneEvent listener (#41) 5697313

+ await oneEvent('a', 'click')
+ console.log('link was clicked')

Add support for once (#40) 39dcce7

+ delegate('a', 'click', alert, {once: true})

v5.0.0...v6.0.0

v5.0.0

31 Aug 03:22
Compare
Choose a tag to compare

Breaking changes

Migration

Listener removal

v3 (old)

const delegation = delegate(document, 'a', 'click', console.log);
delegation.destroy();

v4 (old)

const controller = delegate(document, 'a', 'click', console.log);
controller.abort();

v5 (new)

This was already possible in v4, so if you were using this pattern, you don't need to change anything.

const controller = new AbortController();
delegate(document, 'a', 'click', console.log, {signal: controller.signal});
controller.abort();

v4.0.1...v5.0.0

v4.0.1

26 Jun 05:48
Compare
Choose a tag to compare

v4.0.0...v4.0.1

v4.0.0

23 Jun 16:24
Compare
Choose a tag to compare

Breaking changes

Migration

Listener removal

Before:

const delegation = delegate(document, 'a', 'click', console.log);
delegation.destroy();

After:

const controller = delegate(document, 'a', 'click', console.log);
controller.abort();

// or provide your own signal

const controller = new AbortController();
delegate(document, 'a', 'click', console.log, {signal: controller.signal});
controller.abort();

Types

Before:

import delegate from 'delegate-it'
function listener(event: delegate.Event) {}

After:

import delegate, {DelegateEvent} from 'delegate-it'
function listener(event: DelegateEvent) {}

v3.0.1...v4.0.0

v3.0.1

13 May 14:50
Compare
Choose a tag to compare

v3.0.0...v3.0.1

v3.0.0

10 Apr 12:16
Compare
Choose a tag to compare
  • Make it more strongly-typed when used with TypeScript (#25) cceddeb
  • Improve type inference for the listener callback (#19) 46a07f7

This release is a breaking change only for TypeScript users, making the types more strict and exact. Example upgrade:

v2-

delegate(document, 'button.primary', 'click', event => {
   // event is Event
   // event.delegateTarget is HTMLElement
});
delegate<HTMLButtonElement, MouseEvent>(document, 'button.primary', 'click', event => {
   // event is MouseEvent
   // event.delegateTarget is HTMLButtonElement
});

v3+

As long as the selector correctly includes the tag name, typed-query-selector will parse it to detect the expected element type. Events are matched via GlobalEventHandlersEventMap as was already documented in readme.

delegate(document, 'button.primary', 'click', event => {
   // event is MouseEvent, automatically
   // event.delegateTarget is HTMLButtonElement, automatically parsing the selector
});

v2.0.2...v3.0.0