delegate-it

DOM event delegation, in <1KB

MIT License

Downloads
48K
Stars
189
Committers
18

Bot releases are hidden (Show)

delegate-it - Latest Release

Published by fregante 7 months ago

  • Add support for TypeScript 5.4 (#51) 9cf1d7a

https://github.com/fregante/delegate-it/compare/v6.0.1...v6.1.0

delegate-it -

Published by fregante over 1 year ago

delegate-it -

Published by fregante over 1 year ago

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})

https://github.com/fregante/delegate-it/compare/v5.0.0...v6.0.0

delegate-it -

Published by fregante about 2 years ago

Breaking changes

  • Don't return AbortController (#32) 8a6c2f2

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();

https://github.com/fregante/delegate-it/compare/v4.0.1...v5.0.0

delegate-it -

Published by fregante over 2 years ago

delegate-it - v4.0.0

Published by fregante over 2 years ago

Breaking changes

  • Only accept iterables, not any array-likes ec3232d by @fregante
  • Output modern code 6ac66e2 by @fregante
  • Return AbortController instead of {destroy()} + support signal (#28) 4f3d7ea by @cheap-glitch

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) {}

https://github.com/fregante/delegate-it/compare/v3.0.1...v4.0.0

delegate-it -

Published by fregante over 2 years ago

  • Update dev dependencies + lint 9bbdb15
  • Ignore unsupported once option (#29) 0081742
  • Add TSDoc for options parameter (#27) ec81f44

https://github.com/fregante/delegate-it/compare/v3.0.0...v3.0.1

delegate-it -

Published by fregante over 3 years ago

  • 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
});

https://github.com/fregante/delegate-it/compare/v2.0.2...v3.0.0

delegate-it -

Published by fregante almost 4 years ago

Patches

  • Add support for events triggered on text nodes: #21
delegate-it -

Published by fregante about 4 years ago

  • Don't attach events directly to document 8795011
delegate-it -

Published by fregante over 4 years ago

Major Changes

  • Require the base parameter: https://github.com/fregante/delegate-it/issues/15 7c9b6c341a67ebce6fc9037f808dd36fc6968df6
  • Always return a single subscription, never an array: 357bcc234939e2fb08f2f5e17d21e7b3c26ed465
  • Turn into ES Module; drop CJS file: #17

Patches

  • Clarify source by extracting ledger manager from main function: 9624053b1ec1515a52ce42da16497bf3cb89311f

This should also avoid memory leak because apparently there was a bug in the removal process.

delegate-it -

Published by fregante over 5 years ago

Minor Changes

  • Make the TypeScript types stricter: #5

Patches

  • Restore partial IE 11 support #12
  • Add support for AddEventListenerOptions deduplication (lightweight-ly): #11

Credits

Huge thanks to @nickytonline and @stof for helping!

delegate-it -

Published by fregante over 5 years ago

Patches

  • Fix TypeScript types: a34d85f20fcb28f3485fcd52cd5310b103c446d3
delegate-it -

Published by fregante over 5 years ago

Initial release

delegate-it -

Published by fregante over 5 years ago

Patches

  • Fix some TypeScript types: #2
  • Improve single-element detection: #4
  • Ensure that destroy is always returned: 3f54e6dde0b34f58d7b1b78020314fe913303690