Skip to content

Commit

Permalink
refactor: minor rename
Browse files Browse the repository at this point in the history
  • Loading branch information
motss committed Nov 6, 2021
1 parent 827b063 commit 873cd06
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions src/__tests__/helpers/dispatch-custom-event.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { expect } from '@open-wc/testing';

import { dispatchCustomEvent } from '../../helpers/dispatch-custom-event';
import type { SupportedCustomEvent } from '../../typings';
import type { SupportedCustomEventDetail } from '../../typings';
import { messageFormatter } from '../test-utils/message-formatter';

type A = [SupportedCustomEvent['changed'] | undefined, SupportedCustomEvent['changed'] | null];
type A = [SupportedCustomEventDetail['changed'] | undefined, SupportedCustomEventDetail['changed'] | null];

describe(dispatchCustomEvent.name, () => {
const cases: A[] = [
Expand All @@ -26,13 +26,13 @@ describe(dispatchCustomEvent.name, () => {
messageFormatter('dispatches custom event (detail=%j)', a),
async () => {
const [testDetail, expected] = a;
const testEventName: keyof SupportedCustomEvent = 'changed';
const testEventName: keyof SupportedCustomEventDetail = 'changed';

const el = document.createElement('div');

const done = new Promise<SupportedCustomEvent['changed']>((resolve) => {
const done = new Promise<SupportedCustomEventDetail['changed']>((resolve) => {
el.addEventListener(testEventName, (ev) => {
resolve((ev as CustomEvent<SupportedCustomEvent['changed']>).detail);
resolve((ev as CustomEvent<SupportedCustomEventDetail['changed']>).detail);
}, { once: true });
});

Expand Down
6 changes: 3 additions & 3 deletions src/helpers/dispatch-custom-event.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { SupportedCustomEvent } from '../typings.js';
import type { SupportedCustomEventDetail } from '../typings.js';

export function dispatchCustomEvent<T extends keyof SupportedCustomEvent>(
export function dispatchCustomEvent<T extends keyof SupportedCustomEventDetail>(
target: HTMLElement,
eventName: T,
detail?: SupportedCustomEvent[T]
detail?: SupportedCustomEventDetail[T]
): boolean {
return target.dispatchEvent(new CustomEvent(eventName, {
bubbles: true,
Expand Down
2 changes: 1 addition & 1 deletion src/typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export interface Formatters extends Pick<DatePickerMixinProperties, 'locale'> {

export type InferredFromSet<SetType> = SetType extends Set<infer T> ? T : never;

export interface SupportedCustomEvent {
export interface SupportedCustomEventDetail {
['animation-finished']: null;
['changed']: ChangedEvent;
['date-updated']: DateUpdatedEvent;
Expand Down

0 comments on commit 873cd06

Please sign in to comment.