Skip to content

Commit

Permalink
Add TS support for attaching events to the window object when using u…
Browse files Browse the repository at this point in the history
…seNativeEvent
  • Loading branch information
nruffing committed Jan 6, 2024
1 parent 7c5ab8e commit 8e73a85
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 5 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ onBeforeUnmount(() => {

| Property | Type | Description |
| --- | --- | --- |
| `domEl` | `HTMLElement` | The DOM element to attach the event listener to. |
| `domEl` | `HTMLElement` or `Window & typeof globalThis` | The DOM element or window to attach the event listener to. |
| `event` | `string` | The name of the native event (e.g. `resize`). |
| `listener` | `EventListenerOrEventListenerObject` | The event handler function to attach. This is the same type as the browser API [`addEventListener.listener` parameter](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#the_event_listener_callback). |
| `options` | `boolean`, `AddEventListenerOptions` or `undefined` | Optional. This is the same type as the browser API [`addEventListener.options` parameter](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#options). |
Expand All @@ -148,6 +148,9 @@ The following debounce behavior modes are available via the `DebounceMode` enum.

## Release Notes

### v1.3.0
* Add TS support for attaching events to the window object when using `useNativeEvent`.

### v1.2.0
* Add debug logging level
* Additional source documentation
Expand Down
1 change: 1 addition & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"shiki",
"showcolumnselection",
"typecheck",
"typeof",
"vitest",
"vnode",
"vuejs",
Expand Down
1 change: 0 additions & 1 deletion lib/composables/useDebounce.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { expect, test, describe } from 'vitest'
// import { expectTimestampCloseEnough } from '../../test-util/timestampUtil'
import { useDebounce, DebounceMode } from './useDebounce'
import { log } from '../logger'
import { nativeEventVueOptions } from '../NativeEventVue'

interface DebounceTestCall {
delay: number
Expand Down
4 changes: 2 additions & 2 deletions lib/composables/useNativeEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export type NativeEvent = { destroy: () => void } | undefined

/**
* Composable to attach an HTML native event to an element.
* @param domEl The DOM element to attach the event listener to.
* @param domEl The DOM element or window to attach the event listener to.
* @param event The name of the native event (e.g. `resize`).
* @param listener The event handler function to attach. This is the same type as the browser
* API [`addEventListener.listener` parameter](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#the_event_listener_callback).
Expand All @@ -19,7 +19,7 @@ export type NativeEvent = { destroy: () => void } | undefined
* @returns {@link NativeEvent} object with a destroy method to remove the event listener.
*/
export function useNativeEvent(
domEl: HTMLElement,
domEl: HTMLElement | (Window & typeof globalThis),
event: string,
listener: EventListenerOrEventListenerObject,
options?: boolean | AddEventListenerOptions,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "native-event-vue",
"version": "1.2.0",
"version": "1.3.0",
"type": "module",
"private": false,
"description": "Directives and composables for wiring up and debouncing native HTML events in Vue.",
Expand Down

0 comments on commit 8e73a85

Please sign in to comment.