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

@ -6,7 +6,7 @@ import { Animation, AnimationBuilder, NavDirection, NavOptions } from '../../int
const iosTransitionAnimation = () => import('./ios.transition');
const mdTransitionAnimation = () => import('./md.transition');
export function transition(opts: TransitionOptions): Promise<TransitionResult> {
export const transition = (opts: TransitionOptions): Promise<TransitionResult> => {
return new Promise((resolve, reject) => {
writeTask(() => {
beforeTransition(opts);
@ -22,9 +22,9 @@ export function transition(opts: TransitionOptions): Promise<TransitionResult> {
});
});
});
}
};
function beforeTransition(opts: TransitionOptions) {
const beforeTransition = (opts: TransitionOptions) => {
const enteringEl = opts.enteringEl;
const leavingEl = opts.leavingEl;
@ -39,27 +39,27 @@ function beforeTransition(opts: TransitionOptions) {
if (leavingEl) {
setPageHidden(leavingEl, false);
}
}
};
async function runTransition(opts: TransitionOptions): Promise<TransitionResult> {
const runTransition = async (opts: TransitionOptions): Promise<TransitionResult> => {
const animationBuilder = await getAnimationBuilder(opts);
const ani = (animationBuilder)
? animation(animationBuilder, opts)
: noAnimation(opts); // fast path for no animation
return ani;
}
};
function afterTransition(opts: TransitionOptions) {
const afterTransition = (opts: TransitionOptions) => {
const enteringEl = opts.enteringEl;
const leavingEl = opts.leavingEl;
enteringEl.classList.remove('ion-page-invisible');
if (leavingEl !== undefined) {
leavingEl.classList.remove('ion-page-invisible');
}
}
};
async function getAnimationBuilder(opts: TransitionOptions): Promise<AnimationBuilder | undefined> {
const getAnimationBuilder = async (opts: TransitionOptions): Promise<AnimationBuilder | undefined> => {
if (!opts.leavingEl || !opts.animated || opts.duration === 0) {
return undefined;
}
@ -71,9 +71,9 @@ async function getAnimationBuilder(opts: TransitionOptions): Promise<AnimationBu
: (await mdTransitionAnimation()).mdTransitionAnimation;
return builder;
}
};
async function animation(animationBuilder: AnimationBuilder, opts: TransitionOptions): Promise<TransitionResult> {
const animation = async (animationBuilder: AnimationBuilder, opts: TransitionOptions): Promise<TransitionResult> => {
await waitForReady(opts, true);
const trans = await import('../animation').then(mod => mod.create(animationBuilder, opts.baseEl, opts));
@ -90,9 +90,9 @@ async function animation(animationBuilder: AnimationBuilder, opts: TransitionOpt
hasCompleted: trans.hasCompleted,
animation: trans
};
}
};
async function noAnimation(opts: TransitionOptions): Promise<TransitionResult> {
const noAnimation = async (opts: TransitionOptions): Promise<TransitionResult> => {
const enteringEl = opts.enteringEl;
const leavingEl = opts.leavingEl;
@ -104,29 +104,29 @@ async function noAnimation(opts: TransitionOptions): Promise<TransitionResult> {
return {
hasCompleted: true
};
}
};
async function waitForReady(opts: TransitionOptions, defaultDeep: boolean) {
const waitForReady = async (opts: TransitionOptions, defaultDeep: boolean) => {
const deep = opts.deepWait !== undefined ? opts.deepWait : defaultDeep;
const promises = deep ? [
deepReady(opts.enteringEl),
deepReady(opts.leavingEl),
] : [
shallowReady(opts.enteringEl),
shallowReady(opts.leavingEl),
];
shallowReady(opts.enteringEl),
shallowReady(opts.leavingEl),
];
await Promise.all(promises);
await notifyViewReady(opts.viewIsReady, opts.enteringEl);
}
};
async function notifyViewReady(viewIsReady: undefined | ((enteringEl: HTMLElement) => Promise<any>), enteringEl: HTMLElement) {
const notifyViewReady = async (viewIsReady: undefined | ((enteringEl: HTMLElement) => Promise<any>), enteringEl: HTMLElement) => {
if (viewIsReady) {
await viewIsReady(enteringEl);
}
}
};
function playTransition(trans: Animation, opts: TransitionOptions): Promise<Animation> {
const playTransition = (trans: Animation, opts: TransitionOptions): Promise<Animation> => {
const progressCallback = opts.progressCallback;
const promise = new Promise<Animation>(resolve => trans.onFinish(resolve));
@ -145,19 +145,19 @@ function playTransition(trans: Animation, opts: TransitionOptions): Promise<Anim
}
// create a callback for when the animation is done
return promise;
}
};
function fireWillEvents(enteringEl: HTMLElement | undefined, leavingEl: HTMLElement | undefined) {
const fireWillEvents = (enteringEl: HTMLElement | undefined, leavingEl: HTMLElement | undefined) => {
lifecycle(leavingEl, LIFECYCLE_WILL_LEAVE);
lifecycle(enteringEl, LIFECYCLE_WILL_ENTER);
}
};
function fireDidEvents(enteringEl: HTMLElement | undefined, leavingEl: HTMLElement | undefined) {
const fireDidEvents = (enteringEl: HTMLElement | undefined, leavingEl: HTMLElement | undefined) => {
lifecycle(enteringEl, LIFECYCLE_DID_ENTER);
lifecycle(leavingEl, LIFECYCLE_DID_LEAVE);
}
};
export function lifecycle(el: HTMLElement | undefined, eventName: string) {
export const lifecycle = (el: HTMLElement | undefined, eventName: string) => {
if (el) {
const ev = new CustomEvent(eventName, {
bubbles: false,
@ -165,16 +165,16 @@ export function lifecycle(el: HTMLElement | undefined, eventName: string) {
});
el.dispatchEvent(ev);
}
}
};
function shallowReady(el: Element | undefined): Promise<any> {
const shallowReady = (el: Element | undefined): Promise<any> => {
if (el && (el as any).componentOnReady) {
return (el as any).componentOnReady();
}
return Promise.resolve();
}
};
export async function deepReady(el: any | undefined): Promise<void> {
export const deepReady = async (el: any | undefined): Promise<void> => {
const element = el as any;
if (element) {
if (element.componentOnReady != null) {
@ -185,9 +185,9 @@ export async function deepReady(el: any | undefined): Promise<void> {
}
await Promise.all(Array.from(element.children).map(deepReady));
}
}
};
export function setPageHidden(el: HTMLElement, hidden: boolean) {
export const setPageHidden = (el: HTMLElement, hidden: boolean) => {
if (hidden) {
el.setAttribute('aria-hidden', 'true');
el.classList.add('ion-page-hidden');
@ -196,13 +196,13 @@ export function setPageHidden(el: HTMLElement, hidden: boolean) {
el.removeAttribute('aria-hidden');
el.classList.remove('ion-page-hidden');
}
}
};
function setZIndex(
const setZIndex = (
enteringEl: HTMLElement | undefined,
leavingEl: HTMLElement | undefined,
direction: NavDirection | undefined,
) {
) => {
if (enteringEl !== undefined) {
enteringEl.style.zIndex = (direction === 'back')
? '99'
@ -211,7 +211,7 @@ function setZIndex(
if (leavingEl !== undefined) {
leavingEl.style.zIndex = '100';
}
}
};
export interface TransitionOptions extends NavOptions {
progressCallback?: ((ani: Animation | undefined) => void);