perf(all): minify better by using arrow functions (#18730)

This commit is contained in:
Manu MA
2019-07-10 16:33:33 +02:00
committed by Brandy Carney
parent 8beeff2c52
commit 03c1d19e07
99 changed files with 653 additions and 679 deletions

View File

@ -2,27 +2,27 @@ import { EventEmitter } from '@stencil/core';
import { Side } from '../interface';
export function rIC(callback: () => void) {
export const rIC = (callback: () => void) => {
if ('requestIdleCallback' in window) {
(window as any).requestIdleCallback(callback);
} else {
setTimeout(callback, 32);
}
}
};
export function hasShadowDom(el: HTMLElement) {
export const hasShadowDom = (el: HTMLElement) => {
return !!el.shadowRoot && !!(el as any).attachShadow;
}
};
export function findItemLabel(componentEl: HTMLElement) {
export const findItemLabel = (componentEl: HTMLElement) => {
const itemEl = componentEl.closest('ion-item');
if (itemEl) {
return itemEl.querySelector('ion-label');
}
return null;
}
};
export function renderHiddenInput(always: boolean, container: HTMLElement, name: string, value: string | undefined | null, disabled: boolean) {
export const renderHiddenInput = (always: boolean, container: HTMLElement, name: string, value: string | undefined | null, disabled: boolean) => {
if (always || hasShadowDom(container)) {
let input = container.querySelector('input.aux-input') as HTMLInputElement | null;
if (!input) {
@ -35,26 +35,26 @@ export function renderHiddenInput(always: boolean, container: HTMLElement, name:
input.name = name;
input.value = value || '';
}
}
};
export function clamp(min: number, n: number, max: number) {
export const clamp = (min: number, n: number, max: number) => {
return Math.max(min, Math.min(n, max));
}
};
export function assert(actual: any, reason: string) {
export const assert = (actual: any, reason: string) => {
if (!actual) {
const message = 'ASSERT: ' + reason;
console.error(message);
debugger; // tslint:disable-line
throw new Error(message);
}
}
};
export function now(ev: UIEvent) {
export const now = (ev: UIEvent) => {
return ev.timeStamp || Date.now();
}
};
export function pointerCoord(ev: any): {x: number, y: number} {
export const pointerCoord = (ev: any): { x: number, y: number } => {
// get X coordinates for either a mouse click
// or a touch depending on the given event
if (ev) {
@ -68,7 +68,7 @@ export function pointerCoord(ev: any): {x: number, y: number} {
}
}
return { x: 0, y: 0 };
}
};
/**
* @hidden
@ -77,7 +77,7 @@ export function pointerCoord(ev: any): {x: number, y: number} {
* @param side the side
* @param isRTL whether the application dir is rtl
*/
export function isEndSide(side: Side): boolean {
export const isEndSide = (side: Side): boolean => {
const isRTL = document.dir === 'rtl';
switch (side) {
case 'start': return isRTL;
@ -85,24 +85,24 @@ export function isEndSide(side: Side): boolean {
default:
throw new Error(`"${side}" is not a valid value for [side]. Use "start" or "end" instead.`);
}
}
};
export function deferEvent(event: EventEmitter): EventEmitter {
export const deferEvent = (event: EventEmitter): EventEmitter => {
return debounceEvent(event, 0);
}
};
export function debounceEvent(event: EventEmitter, wait: number): EventEmitter {
export const debounceEvent = (event: EventEmitter, wait: number): EventEmitter => {
const original = (event as any)._original || event;
return {
_original: event,
emit: debounce(original.emit.bind(original), wait)
} as EventEmitter;
}
};
export function debounce(func: (...args: any[]) => void, wait = 0) {
export const debounce = (func: (...args: any[]) => void, wait = 0) => {
let timer: any;
return (...args: any[]): any => {
clearTimeout(timer);
timer = setTimeout(func, wait, ...args);
};
}
};