{"id":22296430,"url":"https://github.com/knowledgecode/delegate","last_synced_at":"2026-04-19T10:02:24.255Z","repository":{"id":35088466,"uuid":"203373333","full_name":"knowledgecode/delegate","owner":"knowledgecode","description":"Event delegation library with support for Web Components","archived":false,"fork":false,"pushed_at":"2026-03-22T00:03:16.000Z","size":616,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-03-22T14:14:52.383Z","etag":null,"topics":["debounce","delegation","dom","event","shadowdom","throttle","typescript","webcomponents"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/knowledgecode.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2019-08-20T12:38:32.000Z","updated_at":"2026-03-22T00:03:12.000Z","dependencies_parsed_at":"2024-12-03T17:45:42.879Z","dependency_job_id":"cab2477d-d1ad-4c63-b855-90c368b58616","html_url":"https://github.com/knowledgecode/delegate","commit_stats":{"total_commits":52,"total_committers":2,"mean_commits":26.0,"dds":"0.038461538461538436","last_synced_commit":"00fd54f11294b9365b09466a812c7b9e5ae618c3"},"previous_names":[],"tags_count":34,"template":false,"template_full_name":null,"purl":"pkg:github/knowledgecode/delegate","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knowledgecode%2Fdelegate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knowledgecode%2Fdelegate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knowledgecode%2Fdelegate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knowledgecode%2Fdelegate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/knowledgecode","download_url":"https://codeload.github.com/knowledgecode/delegate/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knowledgecode%2Fdelegate/sbom","scorecard":{"id":564775,"data":{"date":"2025-08-11","repo":{"name":"github.com/knowledgecode/delegate","commit":"3eb61b56c038da24c8d01eddbef672b19e42eedb"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":4,"checks":[{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Code-Review","score":0,"reason":"Found 0/12 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Maintained","score":4,"reason":"5 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 4","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/ci.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Pinned-Dependencies","score":3,"reason":"dependency not pinned by hash detected -- score normalized to 3","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/knowledgecode/delegate/ci.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:19: update your workflow using https://app.stepsecurity.io/secureworkflow/knowledgecode/delegate/ci.yml/master?enable=pin","Info:   0 out of   2 GitHub-owned GitHubAction dependencies pinned","Info:   1 out of   1 npmCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 22 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-20T14:40:51.552Z","repository_id":35088466,"created_at":"2025-08-20T14:40:51.552Z","updated_at":"2025-08-20T14:40:51.552Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32002361,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-18T20:23:30.271Z","status":"online","status_checked_at":"2026-04-19T02:00:07.110Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["debounce","delegation","dom","event","shadowdom","throttle","typescript","webcomponents"],"created_at":"2024-12-03T17:45:34.226Z","updated_at":"2026-04-19T10:02:24.248Z","avatar_url":"https://github.com/knowledgecode.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Delegate\n\n[![build](https://github.com/knowledgecode/delegate/actions/workflows/ci.yml/badge.svg)](https://github.com/knowledgecode/delegate/actions/workflows/ci.yml)\n[![npm](https://img.shields.io/npm/v/@knowledgecode/delegate)](https://www.npmjs.com/package/@knowledgecode/delegate)\n\nEvent delegation library with support for Web Components.\n\n## Features\n\n- **🎯 Event Delegation**: Efficient event handling with automatic bubbling capture\n- **🌐 Web Components Support**: Shadow DOM traversal with `\u003e\u003e` selector syntax\n- **⚙️  Passive Listeners**: Support for passive event listeners with `:passive` syntax\n- **⚡ Performance Utilities**: Built-in debounce and throttle functions\n- **🔗 jQuery-like API**: Familiar method chaining interface for easy adoption\n- **💾 Memory Efficient**: WeakMap-based caching prevents memory leaks\n- **📦 TypeScript Native**: Full TypeScript support with comprehensive type definitions\n\n## Notice\n\nThis library is under active development and may introduce breaking changes frequently.\n\n## Installation\n\n### Via npm\n\n```shell\nnpm i @knowledgecode/delegate\n```\n\n### Via CDN (ES Modules)\n\nFor modern browsers with ES modules support, you can import directly from a CDN:\n\n#### jsDelivr\n\n```html\n\u003cscript type=\"module\"\u003e\n  import { delegate } from 'https://cdn.jsdelivr.net/npm/@knowledgecode/delegate/+esm';\n\n  delegate(document)\n    .on('click', '.button', () =\u003e {\n      alert('Clicked!');\n    });\n\u003c/script\u003e\n```\n\n#### unpkg\n\n```html\n\u003cscript type=\"module\"\u003e\n  import { delegate } from 'https://unpkg.com/@knowledgecode/delegate?module';\n\n  delegate(document)\n    .on('click', '.button', () =\u003e {\n      alert('Clicked!');\n    });\n\u003c/script\u003e\n```\n\n**Note**: CDN imports work in modern browsers that support ES modules. For older browsers, please use the npm package with a bundler.\n\n## Usage\n\n```typescript\nimport { delegate } from '@knowledgecode/delegate';\n\ndelegate(document)\n  .on('click', '.button', () =\u003e {\n    alert('Clicked!');\n  });\n```\n\n## delegate\n\n### `delegate(baseTarget)`\n\nCreates or retrieves a delegate instance for the specified event target.\n\n- baseTarget\n  - type: `Window | Document | Element | DocumentFragment`\n  - The base event target for delegation. This is the root element where event listeners are registered using event capture.\n\n```typescript\nimport { delegate } from '@knowledgecode/delegate';\n\nconst doc1 = delegate(document);\nconst doc2 = delegate(document);\n\n// Instances created from the same EventTarget are identical unless the previous instance is destroyed\nif (doc1 === doc2) {\n  alert('doc1 and doc2 are the same instance');\n}\n```\n\n### `on(eventName, selector, handler)`\n\nAdds an event listener to the specified event with optional selector for delegation.\n\n- eventName\n  - type: `string`\n  - Name of the event to listen for\n- selector\n  - type: `string`\n  - CSS selector for delegation\n- handler\n  - type: `DelegateEventListener`\n  - Event handler function to be executed\n\n```typescript\nimport { delegate } from '@knowledgecode/delegate';\n\ndelegate(document.body)\n  .on('click', '#button', () =\u003e {\n    alert('The button is clicked!');\n  });\n\n// Omit the selector when the base event target itself handles the event:\ndelegate(document.body)\n  .on('click', () =\u003e {\n    alert('The body is clicked');\n  });\n```\n\n#### DelegateEventListener\n\n`DelegateEventListener` is a function that takes a `DelegateEvent` as an argument. Details about `DelegateEvent` are described later.\n\n```typescript\nimport { delegate } from '@knowledgecode/delegate';\n\ndelegate(document.body)\n  .on('click', '#button', evt =\u003e {\n    evt.preventDefault();\n  });\n```\n\n### `one(eventName, selector, handler)`\n\nAdds a one-time event listener that will be automatically removed after execution.\n\n- eventName\n  - type: `string`\n  - Name of the event to listen for\n- selector\n  - type: `string`\n  - CSS selector for delegation\n- handler\n  - type: `DelegateEventListener`\n  - Event handler function to be executed once\n\n```typescript\nimport { delegate } from '@knowledgecode/delegate';\n\ndelegate(document.querySelector('.container'))\n  .one('click', '#button', () =\u003e {\n    alert('The button is clicked!');\n  });\n\n// Omit the selector when the base event target itself handles the event:\ndelegate(document.querySelector('.container'))\n  .one('click', () =\u003e {\n    alert('The container is clicked');\n  });\n```\n\n### `off([eventName[, selector[, handler]]])`\n\nRemoves event listeners based on the specified parameters.\n\n- eventName\n  - type: `string`\n  - Name of the event to remove\n- selector\n  - type: `string`\n  - CSS selector for delegation\n- handler\n  - type: `DelegateEventListener`\n  - Event handler function to remove\n\n```typescript\nimport { delegate } from '@knowledgecode/delegate';\n\nconst handler1 = () =\u003e alert('Clicked!');\nconst handler2 = () =\u003e alert('Clicked!');\nconst handler3 = () =\u003e alert('Mouse Over!');\n\ndelegate(document.body)\n  .on('click', '#button', handler1)         // event 1\n  .on('click', '#button', handler2)         // event 2\n  .on('mouseover', '#button', handler3)     // event 3\n  .on('click', handler1);                   // event 4\n\n// To remove only event 1:\ndelegate(document.body).off('click', '#button', handler1);\n\n// To remove only event 4:\ndelegate(document.body).off('click', handler1);\n\n// To remove all click events registered to #button (event 1 and 2):\ndelegate(document.body).off('click', '#button');\n\n// To remove all click events (event 1, 2 and 4):\ndelegate(document.body).off('click');\n\n// To remove all events:\ndelegate(document.body).off();\n```\n\n### `clear()`\n\nClears all event listeners and removes the delegator from cache. The difference from `off()` is that it also removes the cached delegate instance from the library's internal storage.\n\n```typescript\nimport { delegate } from '@knowledgecode/delegate';\n\nconst handler1 = () =\u003e alert('Clicked!');\nconst handler2 = () =\u003e alert('Clicked!');\nconst handler3 = () =\u003e alert('Mouse Over!');\n\nconst body = delegate(document.body);\n\nbody\n  .on('click', '#button', handler1)\n  .on('click', '#button', handler2)\n  .on('mouseover', '#button', handler3)\n  .on('click', handler1);\n\n// Completely removes including the delegate instance\nbody.clear();\n\nconst body2 = delegate(document.body);\n\nif (body !== body2) {\n  alert('body and body2 are different instances');\n}\n```\n\n## DelegateEvent\n\n`DelegateEvent` is the event object passed to event handlers.\n\n### `preventDefault()`\n\nPrevents the default action of the event.\n\n```typescript\ndelegate(document)\n  .on('click', 'input[type=\"submit\"]', evt =\u003e {\n    // Prevents submission\n    evt.preventDefault();\n  });\n```\n\n### `stopPropagation()`\n\nStops the propagation of the event.\n\n```typescript\ndelegate(document)\n  .on('click', '.button \u003e .label', evt =\u003e {\n    evt.stopPropagation();\n  })\n  .on('click', '.button', evt =\u003e {\n    // This event handler will not be called\n  });\n```\n\n### `stopImmediatePropagation()`\n\nStops the propagation of the event and prevents any further listeners from being called. Event handlers for the same element are called in the order they were registered. If `stopImmediatePropagation` is executed in an earlier event handler, subsequent event handlers will not be called.\n\n```typescript\ndelegate(document)\n  .on('click', '.item', evt =\u003e {\n    evt.stopImmediatePropagation();\n  })\n  .on('click', '.item', evt =\u003e {\n    // This event handler will not be called\n  });\n```\n\n### `nativeEvent`\n\nThe native event object.\n\n```typescript\ndelegate(document)\n  .on('mousedown', '#area', evt =\u003e {\n    if (evt.nativeEvent.pageX \u003c 48 \u0026\u0026 evt.nativeEvent.pageY \u003c 48) {\n      alert('Shoot!');\n    }\n  });\n```\n\n\u003e **Note**: The `originalEvent` property is deprecated. Please use `nativeEvent` instead. The `originalEvent` property is still available for backward compatibility but will be removed in a future version.\n\n### `currentTarget`\n\nThe current target of the event (i.e., the element where the event listener is attached).\n\n**Note**: This property represents the same target as the `baseTarget` parameter passed to the `delegate()` function. In event delegation, the `baseTarget` is where the event listener is registered, and during event handling, `evt.currentTarget` refers to that same target.\n\n```typescript\ndelegate(document)\n  .on('click', '.button', evt =\u003e {\n    // evt.currentTarget is the same as the baseTarget (document)\n    if (evt.currentTarget === document) {\n      alert('The currentTarget equals to the baseTarget (document).');\n    }\n  });\n```\n\n### `delegateTarget`\n\nThe delegate target of the event.\n\n```typescript\ndelegate(document)\n  .on('click', '.button', evt =\u003e {\n    if (evt.delegateTarget === document.querySelector('.button')) {\n      alert('The delegateTarget equals to the button.');\n    }\n  });\n```\n\n### `target`\n\nThe original target of the event.\n\n```typescript\ndelegate(document)\n  .on('click', '.button', evt =\u003e {\n    if (evt.target !== document.querySelector('.button')) {\n      alert('The target does not equal to the button.');\n    }\n  })\n  .on('click', '.button \u003e .label', evt =\u003e {\n    if (evt.target === document.querySelector('.button \u003e .label')) {\n      alert('The target equals to the button\\'s label.');\n    }\n  });\n```\n\n### `detail`\n\nThe detail data associated with the event.\n\n```typescript\nimport { delegate } from '@knowledgecode/delegate';\n\ndelegate(document)\n  .on('click', '.button', evt =\u003e {\n    const customEvent = new CustomEvent('custom:click', {\n      bubbles: true,\n      detail: 'Clicked!'\n    });\n    document.dispatchEvent(customEvent);\n  })\n  .on('custom:click', evt =\u003e {\n    alert(evt.detail);  // Clicked!\n  });\n```\n\n## Utils\n\n### pierce(destination, ev[, data])\n\nPierces an event through shadow DOM boundaries by dispatching a custom event to the specified destination. This is primarily used within Web Components to propagate events that don't naturally pierce shadow DOM boundaries.\n\n- destination\n  - type: `HTMLElement`\n  - The target to pierce the event to.\n- ev\n  - type: `Event | DelegateEvent`\n  - The native event or DelegateEvent instance to be pierced.\n- data\n  - type: `unknown`\n  - Optional data to be included in the event detail.\n\n```typescript\nimport { pierce } from '@knowledgecode/delegate';\n\n// Inside a Web Component\nclass MyComponent extends HTMLElement {\n  connectedCallback() {\n    this.shadowRoot.querySelector('input').addEventListener('change', (evt) =\u003e {\n      // Pierce the change event to the Light DOM\n      pierce(this, evt);\n    });\n  }\n}\n```\n\nSee the [Using with Web Components](#using-with-web-components) section for more detailed examples.\n\n\u003e **Note**: The `dispatch()` function is deprecated. Please use `pierce()` instead. The `dispatch()` function is still available for backward compatibility but will be removed in a future version.\n\n### debounce(handler, delay)\n\nDebounce function to limit the rate at which a function can fire.\n\n- handler\n  - type: `EventListener | DelegateEventListener`\n  - The function to be debounced, typically an EventListener or DelegateEventListener.\n- delay\n  - type: `number`\n  - The time in milliseconds to wait before executing the function after the last call.\n\n```typescript\nimport { delegate, debounce, DelegateEvent } from '@knowledgecode/delegate';\n\ndelegate(window)\n  .on('resize', debounce((evt: DelegateEvent) =\u003e {\n    // Process 300ms after the last resize event occurred\n    console.log((evt.target as Window).innerWidth);\n  }, 300));\n```\n\n### throttle(handler, interval)\n\nThrottle function to limit the execution of a function to once every specified interval.\n\n- handler\n  - type: `EventListener | DelegateEventListener`\n  - The function to be throttled, typically an EventListener or DelegateEventListener.\n- interval\n  - type: `number`\n  - The time in milliseconds to wait before allowing the function to be called again.\n\n```typescript\nimport { delegate, throttle, DelegateEvent } from '@knowledgecode/delegate';\n\ndelegate(window)\n  .on('scroll', throttle((evt: DelegateEvent) =\u003e {\n    // Throttle scroll events and process every 100ms\n    console.log((evt.target as Window).scrollY);\n  }, 100));\n```\n\n## Using with Web Components\n\nThis library can also be used with Web Components. Here's an example using it within a Web Component created with `Lit`:\n\n```typescript\nimport { LitElement, html } from 'lit';\nimport { customElement } from 'lit/decorators.js';\n\nimport { delegate, pierce } from '@knowledgecode/delegate';\n\n@customElement('my-component')\nexport class MyComponent extends LitElement {\n  connectedCallback () {\n    super.connectedCallback();\n\n    delegate(this.renderRoot)\n      .on('change', '.check', evt =\u003e {\n        // Pierce events that don't bubble through shadow DOM boundaries by default\n        // This is not needed for events like click that naturally bubble through shadow DOM\n        pierce(this, evt);\n      })\n  }\n\n  disconnectedCallback(): void {\n    super.disconnectedCallback();\n    // Release delegate events\n    delegate(this.renderRoot).clear();\n  }\n\n  render () {\n    return html`\n      \u003cinput type=\"checkbox\" class=\"check\"\u003e\n    `;\n  }\n}\n```\n\nEvents propagated from Web Components can be received on the Light DOM side:\n\n```typescript\nimport { delegate } from '@knowledgecode/delegate';\n\ndelegate(document)\n  .on('change', 'my-component \u003e\u003e .check', () =\u003e {\n    console.log('This is a change event propagated from the checkbox inside my-component');\n  })\n  .on('change', '.check', () =\u003e {\n    console.log('This is a change event propagated from a checkbox');\n  });\n```\n\n`\u003e\u003e` is a custom selector that represents Shadow DOM boundaries. Since CSS selectors cannot normally pierce Shadow DOM boundaries, specifying `my-component .check` would not receive events. While this library allows you to receive events by simply specifying `.check`, when multiple `.check` elements exist, you can narrow down the event source by specifying `my-component \u003e\u003e .check`, which is convenient.\n\nThe `\u003e\u003e` selector also supports nested Web Components:\n\n```typescript\nimport { delegate } from '@knowledgecode/delegate';\n\ndelegate(document)\n  .on('change', 'div other-component \u003e\u003e my-component \u003e\u003e .check', () =\u003e {\n    console.log('This is a change event propagated from the checkbox in my-component inside other-component under div');\n  });\n```\n\n## Passive Listener\n\nYou can define passive event handlers by adding `:passive` to the `eventName`:\n\n```typescript\ndelegate(document)\n  .on('touchstart:passive', '.touch-area', evt =\u003e {\n    // Error (passive event handlers cannot prevent this event)\n    evt.preventDefault();\n  });\n```\n\n`touchstart:passive` is clearly distinguished from `touchstart`. When removing this event handler with `off()`, you must specify `touchstart:passive` rather than `touchstart` for the `eventName`.\n\n## Method Chaining\n\nThis library supports method chaining:\n\n```typescript\ndelegate(document)\n  .on('mousedown', '#button', () =\u003e {\n    alert('Mouse down!');\n  })\n  .on('mouseover', '#button', () =\u003e {\n    alert('Mouse over!');\n  })\n  .on('mouseup', '#button', () =\u003e {\n    alert('Mouse up!');\n  });\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fknowledgecode%2Fdelegate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fknowledgecode%2Fdelegate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fknowledgecode%2Fdelegate/lists"}