Skip to content

Commit a2ce019

Browse files
committed
feat(runtime): ability to hook into creating CustomEvent, so vue binding can lowercase it
1 parent a06a941 commit a2ce019

5 files changed

Lines changed: 6 additions & 2 deletions

File tree

src/client/client-window.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export const plt: d.PlatformRuntime = {
1616
raf: h => requestAnimationFrame(h),
1717
ael: (el, eventName, listener, opts) => el.addEventListener(eventName, listener, opts),
1818
rel: (el, eventName, listener, opts) => el.removeEventListener(eventName, listener, opts),
19+
ce: (eventName, opts) => new CustomEvent(eventName, opts),
1920
};
2021

2122
export const supportsShadow = BUILD.shadowDomShim && BUILD.shadowDom ? /*@__PURE__*/ (() => (doc.head.attachShadow + '').indexOf('[native') > -1)() : true;

src/declarations/stencil-private.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1716,6 +1716,7 @@ export interface PlatformRuntime {
17161716
raf: (c: FrameRequestCallback) => number;
17171717
ael: (el: EventTarget, eventName: string, listener: EventListenerOrEventListenerObject, options: boolean | AddEventListenerOptions) => void;
17181718
rel: (el: EventTarget, eventName: string, listener: EventListenerOrEventListenerObject, options: boolean | AddEventListenerOptions) => void;
1719+
ce: (eventName: string, opts?: any) => CustomEvent;
17191720
}
17201721

17211722
export type RefMap = WeakMap<any, HostRef>;

src/hydrate/platform/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ export const plt: d.PlatformRuntime = {
9898
raf: h => requestAnimationFrame(h),
9999
ael: (el, eventName, listener, opts) => el.addEventListener(eventName, listener, opts),
100100
rel: (el, eventName, listener, opts) => el.removeEventListener(eventName, listener, opts),
101+
ce: (eventName, opts) => new win.CustomEvent(eventName, opts),
101102
};
102103

103104
export const supportsShadow = false;

src/runtime/event-emitter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as d from '../declarations';
22
import { BUILD } from '@app-data';
3-
import { consoleDevWarn, win } from '@platform';
3+
import { consoleDevWarn, plt } from '@platform';
44
import { EVENT_FLAGS } from '@utils';
55
import { getElement } from './element';
66

@@ -22,7 +22,7 @@ export const createEvent = (ref: d.RuntimeRef, name: string, flags: number) => {
2222
};
2323

2424
export const emitEvent = (elm: EventTarget, name: string, opts?: CustomEventInit) => {
25-
const ev = new (BUILD.hydrateServerSide ? (win as any).CustomEvent : CustomEvent)(name, opts);
25+
const ev = plt.ce(name, opts);
2626
elm.dispatchEvent(ev);
2727
return ev;
2828
};

src/testing/platform/testing-platform.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export const plt: d.PlatformRuntime = {
1212
raf: h => requestAnimationFrame(h),
1313
ael: (el, eventName, listener, opts) => el.addEventListener(eventName, listener, opts),
1414
rel: (el, eventName, listener, opts) => el.removeEventListener(eventName, listener, opts),
15+
ce: (eventName, opts) => new (win as any).CustomEvent(eventName, opts),
1516
};
1617

1718
export const cssVarShim: d.CssVarShim = false as any;

0 commit comments

Comments
 (0)