Skip to content

Commit

Permalink
feat(platform): add setPlatformHelpers() api
Browse files Browse the repository at this point in the history
Allows for custom elements build to modify how CustomEvents, addEventListener and removeEventListeners are called.
  • Loading branch information
adamdbradley committed May 27, 2021
1 parent 8d580b1 commit f09abe6
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/client/client-window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,26 @@ export const plt: d.PlatformRuntime = {
ce: (eventName, opts) => new CustomEvent(eventName, opts),
};

export const setPlatformHelpers = (helpers: {
jmp?: (c: any) => any;
raf?: (c: any) => number;
ael?: (
el: any,
eventName: string,
listener: any,
options: any,
) => void;
rel?: (
el: any,
eventName: string,
listener: any,
options: any,
) => void;
ce?: (eventName: string, opts?: any) => any;
}) => {
Object.assign(plt, helpers);
};

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

export const supportsListenerOptions = /*@__PURE__*/ (() => {
Expand Down
1 change: 1 addition & 0 deletions src/compiler/transformers/update-stencil-core-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const KEEP_IMPORTS = new Set([
'h',
'setMode',
'getMode',
'setPlatformHelpers',
'Build',
'Env',
'Host',
Expand Down
18 changes: 18 additions & 0 deletions src/declarations/stencil-public-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,24 @@ export declare const setMode: (handler: ResolutionHandler) => void;
*/
export declare function getMode<T = string | undefined>(ref: any): T;

export declare function setPlatformHelpers (helpers: {
jmp?: (c: any) => any;
raf?: (c: any) => number;
ael?: (
el: any,
eventName: string,
listener: any,
options: any,
) => void;
rel?: (
el: any,
eventName: string,
listener: any,
options: any,
) => void;
ce?: (eventName: string, opts?: any) => any;
}): void;

/**
* Get the base path to where the assets can be found. Use `setAssetPath(path)`
* if the path needs to be customized.
Expand Down
20 changes: 20 additions & 0 deletions src/hydrate/platform/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,26 @@ export const plt: d.PlatformRuntime = {
ce: (eventName, opts) => new win.CustomEvent(eventName, opts),
};

export const setPlatformHelpers = (helpers: {
jmp?: (c: any) => any;
raf?: (c: any) => number;
ael?: (
el: any,
eventName: string,
listener: any,
options: any,
) => void;
rel?: (
el: any,
eventName: string,
listener: any,
options: any,
) => void;
ce?: (eventName: string, opts?: any) => any;
}) => {
Object.assign(plt, helpers);
};

export const supportsShadow = false;

export const supportsListenerOptions = false;
Expand Down
1 change: 1 addition & 0 deletions src/internal/stencil-core/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export {
readTask,
setAssetPath,
setMode,
setPlatformHelpers,
State,
Watch,
writeTask,
Expand Down
1 change: 1 addition & 0 deletions src/internal/stencil-core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export {
readTask,
setMode,
setAssetPath,
setPlatformHelpers,
writeTask,
setErrorHandler,
} from '../client/index.js';
1 change: 1 addition & 0 deletions src/testing/platform/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export {
isMemberInElement,
plt,
supportsShadow,
setPlatformHelpers,
registerComponents,
registerContext,
registerModule,
Expand Down
20 changes: 20 additions & 0 deletions src/testing/platform/testing-platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,26 @@ export const plt: d.PlatformRuntime = {
ce: (eventName, opts) => new (win as any).CustomEvent(eventName, opts),
};

export const setPlatformHelpers = (helpers: {
jmp?: (c: any) => any;
raf?: (c: any) => number;
ael?: (
el: any,
eventName: string,
listener: any,
options: any,
) => void;
rel?: (
el: any,
eventName: string,
listener: any,
options: any,
) => void;
ce?: (eventName: string, opts?: any) => any;
}) => {
Object.assign(plt, helpers);
};

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

0 comments on commit f09abe6

Please sign in to comment.