Skip to content

Commit

Permalink
feat(runtime): ability to hook into creating CustomEvent, so vue bind…
Browse files Browse the repository at this point in the history
…ing can lowercase it
  • Loading branch information
adamdbradley committed Jul 22, 2020
1 parent a06a941 commit a2ce019
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/client/client-window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const plt: d.PlatformRuntime = {
raf: h => requestAnimationFrame(h),
ael: (el, eventName, listener, opts) => el.addEventListener(eventName, listener, opts),
rel: (el, eventName, listener, opts) => el.removeEventListener(eventName, listener, opts),
ce: (eventName, opts) => new CustomEvent(eventName, opts),
};

export const supportsShadow = BUILD.shadowDomShim && BUILD.shadowDom ? /*@__PURE__*/ (() => (doc.head.attachShadow + '').indexOf('[native') > -1)() : true;
Expand Down
1 change: 1 addition & 0 deletions src/declarations/stencil-private.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1716,6 +1716,7 @@ export interface PlatformRuntime {
raf: (c: FrameRequestCallback) => number;
ael: (el: EventTarget, eventName: string, listener: EventListenerOrEventListenerObject, options: boolean | AddEventListenerOptions) => void;
rel: (el: EventTarget, eventName: string, listener: EventListenerOrEventListenerObject, options: boolean | AddEventListenerOptions) => void;
ce: (eventName: string, opts?: any) => CustomEvent;
}

export type RefMap = WeakMap<any, HostRef>;
Expand Down
1 change: 1 addition & 0 deletions src/hydrate/platform/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export const plt: d.PlatformRuntime = {
raf: h => requestAnimationFrame(h),
ael: (el, eventName, listener, opts) => el.addEventListener(eventName, listener, opts),
rel: (el, eventName, listener, opts) => el.removeEventListener(eventName, listener, opts),
ce: (eventName, opts) => new win.CustomEvent(eventName, opts),
};

export const supportsShadow = false;
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/event-emitter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as d from '../declarations';
import { BUILD } from '@app-data';
import { consoleDevWarn, win } from '@platform';
import { consoleDevWarn, plt } from '@platform';
import { EVENT_FLAGS } from '@utils';
import { getElement } from './element';

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

export const emitEvent = (elm: EventTarget, name: string, opts?: CustomEventInit) => {
const ev = new (BUILD.hydrateServerSide ? (win as any).CustomEvent : CustomEvent)(name, opts);
const ev = plt.ce(name, opts);
elm.dispatchEvent(ev);
return ev;
};
1 change: 1 addition & 0 deletions src/testing/platform/testing-platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const plt: d.PlatformRuntime = {
raf: h => requestAnimationFrame(h),
ael: (el, eventName, listener, opts) => el.addEventListener(eventName, listener, opts),
rel: (el, eventName, listener, opts) => el.removeEventListener(eventName, listener, opts),
ce: (eventName, opts) => new (win as any).CustomEvent(eventName, opts),
};

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

0 comments on commit a2ce019

Please sign in to comment.