refactor(angular): use arrow functions (#18910)

This commit is contained in:
Manu MA
2019-08-06 14:18:08 +02:00
committed by GitHub
parent 3a22105375
commit f94300cbb3
8 changed files with 24 additions and 24 deletions

View File

@ -5,7 +5,7 @@ import { Config } from './providers/config';
import { IonicWindow } from './types/interfaces'; import { IonicWindow } from './types/interfaces';
import { raf } from './util/util'; import { raf } from './util/util';
export function appInitialize(config: Config, doc: Document, zone: NgZone) { export const appInitialize = (config: Config, doc: Document, zone: NgZone) => {
return (): any => { return (): any => {
const win: IonicWindow | undefined = doc.defaultView as any; const win: IonicWindow | undefined = doc.defaultView as any;
if (win) { if (win) {
@ -36,4 +36,4 @@ export function appInitialize(config: Config, doc: Document, zone: NgZone) {
}); });
} }
}; };
} };

View File

@ -72,7 +72,7 @@ const getClasses = (element: HTMLElement) => {
return classes; return classes;
}; };
function setClasses(element: HTMLElement, classes: string[]) { const setClasses = (element: HTMLElement, classes: string[]) => {
const classList = element.classList; const classList = element.classList;
classList.remove( classList.remove(
@ -84,8 +84,8 @@ function setClasses(element: HTMLElement, classes: string[]) {
'ion-pristine' 'ion-pristine'
); );
classList.add(...classes); classList.add(...classes);
} };
function startsWith(input: string, search: string): boolean { const startsWith = (input: string, search: string): boolean => {
return input.substr(0, search.length) === search; return input.substr(0, search.length) === search;
} };

View File

@ -206,7 +206,7 @@ export class IonVirtualScroll {
} }
} }
function getElement(view: EmbeddedViewRef<VirtualContext>): HTMLElement { const getElement = (view: EmbeddedViewRef<VirtualContext>): HTMLElement => {
const rootNodes = view.rootNodes; const rootNodes = view.rootNodes;
for (let i = 0; i < rootNodes.length; i++) { for (let i = 0; i < rootNodes.length; i++) {
if (rootNodes[i].nodeType === 1) { if (rootNodes[i].nodeType === 1) {
@ -214,7 +214,7 @@ function getElement(view: EmbeddedViewRef<VirtualContext>): HTMLElement {
} }
} }
throw new Error('virtual element was not created'); throw new Error('virtual element was not created');
} };
proxyInputs(IonVirtualScroll, [ proxyInputs(IonVirtualScroll, [
'approxItemHeight', 'approxItemHeight',

View File

@ -65,7 +65,7 @@ export class AngularFrameworkDelegate implements FrameworkDelegate {
} }
} }
export function attachView( export const attachView = (
zone: NgZone, zone: NgZone,
resolver: ComponentFactoryResolver, resolver: ComponentFactoryResolver,
injector: Injector, injector: Injector,
@ -74,7 +74,7 @@ export function attachView(
elRefMap: WeakMap<HTMLElement, any>, elRefMap: WeakMap<HTMLElement, any>,
elEventsMap: WeakMap<HTMLElement, () => void>, elEventsMap: WeakMap<HTMLElement, () => void>,
container: any, component: any, params: any, cssClasses: string[] | undefined container: any, component: any, params: any, cssClasses: string[] | undefined
) { ) => {
const factory = resolver.resolveComponentFactory(component); const factory = resolver.resolveComponentFactory(component);
const childInjector = Injector.create({ const childInjector = Injector.create({
providers: getProviders(params), providers: getProviders(params),
@ -104,7 +104,7 @@ export function attachView(
elRefMap.set(hostElement, componentRef); elRefMap.set(hostElement, componentRef);
elEventsMap.set(hostElement, unbindEvents); elEventsMap.set(hostElement, unbindEvents);
return hostElement; return hostElement;
} };
const LIFECYCLES = [ const LIFECYCLES = [
LIFECYCLE_WILL_ENTER, LIFECYCLE_WILL_ENTER,
@ -114,7 +114,7 @@ const LIFECYCLES = [
LIFECYCLE_WILL_UNLOAD LIFECYCLE_WILL_UNLOAD
]; ];
export function bindLifecycleEvents(zone: NgZone, instance: any, element: HTMLElement) { export const bindLifecycleEvents = (zone: NgZone, instance: any, element: HTMLElement) => {
return zone.run(() => { return zone.run(() => {
const unregisters = LIFECYCLES const unregisters = LIFECYCLES
.filter(eventName => typeof instance[eventName] === 'function') .filter(eventName => typeof instance[eventName] === 'function')
@ -125,11 +125,11 @@ export function bindLifecycleEvents(zone: NgZone, instance: any, element: HTMLEl
}); });
return () => unregisters.forEach(fn => fn()); return () => unregisters.forEach(fn => fn());
}); });
} };
const NavParamsToken = new InjectionToken<any>('NavParamsToken'); const NavParamsToken = new InjectionToken<any>('NavParamsToken');
function getProviders(params: {[key: string]: any}) { const getProviders = (params: {[key: string]: any}) => {
return [ return [
{ {
provide: NavParamsToken, useValue: params provide: NavParamsToken, useValue: params
@ -138,8 +138,8 @@ function getProviders(params: {[key: string]: any}) {
provide: NavParams, useFactory: provideNavParamsInjectable, deps: [NavParamsToken] provide: NavParams, useFactory: provideNavParamsInjectable, deps: [NavParamsToken]
} }
]; ];
} };
function provideNavParamsInjectable(params: {[key: string]: any}) { const provideNavParamsInjectable = (params: {[key: string]: any}) => {
return new NavParams(params); return new NavParams(params);
} };

View File

@ -42,7 +42,7 @@ export class Config {
export const ConfigToken = new InjectionToken<any>('USERCONFIG'); export const ConfigToken = new InjectionToken<any>('USERCONFIG');
function getConfig(): CoreConfig | null { const getConfig = (): CoreConfig | null => {
if (typeof (window as any) !== 'undefined') { if (typeof (window as any) !== 'undefined') {
const Ionic = (window as IonicWindow).Ionic; const Ionic = (window as IonicWindow).Ionic;
if (Ionic && Ionic.config) { if (Ionic && Ionic.config) {
@ -50,4 +50,4 @@ function getConfig(): CoreConfig | null {
} }
} }
return null; return null;
} };

View File

@ -22,7 +22,7 @@ export class DomController {
} }
} }
function getQueue() { const getQueue = () => {
const win = typeof (window as any) !== 'undefined' ? window : null as any; const win = typeof (window as any) !== 'undefined' ? window : null as any;
if (win != null) { if (win != null) {
@ -41,6 +41,6 @@ function getQueue() {
read: (cb: any) => cb(), read: (cb: any) => cb(),
write: (cb: any) => cb() write: (cb: any) => cb()
}; };
} };
export type RafCallback = (timeStamp?: number) => void; export type RafCallback = (timeStamp?: number) => void;

View File

@ -213,7 +213,7 @@ export class NavController {
} }
} }
function getAnimation(direction: RouterDirection, animated: boolean | undefined, animationDirection: 'forward' | 'back' | undefined): NavDirection | undefined { const getAnimation = (direction: RouterDirection, animated: boolean | undefined, animationDirection: 'forward' | 'back' | undefined): NavDirection | undefined => {
if (animated === false) { if (animated === false) {
return undefined; return undefined;
} }
@ -226,7 +226,7 @@ function getAnimation(direction: RouterDirection, animated: boolean | undefined,
return 'forward'; return 'forward';
} }
return undefined; return undefined;
} };
const DEFAULT_DIRECTION = 'auto'; const DEFAULT_DIRECTION = 'auto';
const DEFAULT_ANIMATED = undefined; const DEFAULT_ANIMATED = undefined;

View File

@ -18,7 +18,7 @@
"no-floating-promises": false, "no-floating-promises": false,
"no-invalid-template-strings": true, "no-invalid-template-strings": true,
"ban-export-const-enum": true, "ban-export-const-enum": true,
"only-arrow-functions": true,
"prefer-for-of": false "prefer-for-of": false
} }
} }