refactor(all): avoid using export const enum (#16614)

* refactor(all): avoid using export const enum

fixes #16497

* add tslint
This commit is contained in:
Manu MA
2018-12-06 21:19:49 +01:00
committed by GitHub
parent 95c0b1bac7
commit 119e0c1fd2
24 changed files with 150 additions and 166 deletions

View File

@ -1,11 +1,11 @@
import { Build, Component, Element, Event, EventEmitter, Method, Prop, QueueApi, Watch } from '@stencil/core';
import { ViewLifecycle } from '../..';
import { Animation, AnimationBuilder, ComponentProps, Config, FrameworkDelegate, Gesture, Mode, NavComponent, NavOptions, NavOutlet, NavResult, RouteID, RouteWrite, TransitionDoneFn, TransitionInstruction, ViewController } from '../../interface';
import { Animation, AnimationBuilder, ComponentProps, Config, FrameworkDelegate, Gesture, Mode, NavComponent, NavOptions, NavOutlet, NavResult, RouteID, RouteWrite, RouterDirection, TransitionDoneFn, TransitionInstruction, ViewController } from '../../interface';
import { assert } from '../../utils/helpers';
import { TransitionOptions, lifecycle, setPageHidden, transition } from '../../utils/transition';
import { ViewState, convertToViews, matches } from './view-controller';
import { LIFECYCLE_DID_LEAVE, LIFECYCLE_WILL_LEAVE, LIFECYCLE_WILL_UNLOAD } from './constants';
import { VIEW_STATE_ATTACHED, VIEW_STATE_DESTROYED, VIEW_STATE_NEW, convertToViews, matches } from './view-controller';
@Component({
tag: 'ion-nav',
@ -124,7 +124,7 @@ export class Nav implements NavOutlet {
componentDidUnload() {
for (const view of this.views) {
lifecycle(view.element!, ViewLifecycle.WillUnload);
lifecycle(view.element!, LIFECYCLE_WILL_UNLOAD);
view._destroy();
}
@ -324,7 +324,7 @@ export class Nav implements NavOutlet {
setRouteId(
id: string,
params: ComponentProps | undefined,
direction: number
direction: RouterDirection
): Promise<RouteWrite> {
const active = this.getActiveSync();
if (matches(active, id, params)) {
@ -354,7 +354,7 @@ export class Nav implements NavOutlet {
}
};
if (direction === 0) {
if (direction === 'root') {
finish = this.setRoot(id, params, commonOpts);
} else {
const viewController = this.views.find(v => matches(v, id, params));
@ -364,9 +364,9 @@ export class Nav implements NavOutlet {
...commonOpts,
direction: 'back'
});
} else if (direction === 1) {
} else if (direction === 'forward') {
finish = this.push(id, params, commonOpts);
} else if (direction === -1) {
} else if (direction === 'back') {
finish = this.setRoot(id, params, {
...commonOpts,
direction: 'back',
@ -502,7 +502,7 @@ export class Nav implements NavOutlet {
if (ti.opts!.updateURL !== false && this.useRouter) {
const router = this.win.document.querySelector('ion-router');
if (router) {
const direction = result.direction === 'back' ? -1 : 1;
const direction = result.direction === 'back' ? 'back' : 'forward';
router.navChanged(direction);
}
}
@ -560,7 +560,7 @@ export class Nav implements NavOutlet {
throw new Error('no views in the stack to be removed');
}
if (enteringView && enteringView.state === ViewState.New) {
if (enteringView && enteringView.state === VIEW_STATE_NEW) {
await enteringView.init(this.el);
}
this.postViewInit(enteringView, leavingView, ti);
@ -645,7 +645,7 @@ export class Nav implements NavOutlet {
if (nav && nav !== this) {
throw new Error('inserted view was already inserted');
}
if (view.state === ViewState.Destroyed) {
if (view.state === VIEW_STATE_DESTROYED) {
throw new Error('inserted view was already destroyed');
}
}
@ -749,9 +749,9 @@ export class Nav implements NavOutlet {
// let's make sure, callbacks are zoned
if (destroyQueue && destroyQueue.length > 0) {
for (const view of destroyQueue) {
lifecycle(view.element, ViewLifecycle.WillLeave);
lifecycle(view.element, ViewLifecycle.DidLeave);
lifecycle(view.element, ViewLifecycle.WillUnload);
lifecycle(view.element, LIFECYCLE_WILL_LEAVE);
lifecycle(view.element, LIFECYCLE_DID_LEAVE);
lifecycle(view.element, LIFECYCLE_WILL_UNLOAD);
}
// once all lifecycle events has been delivered, we can safely detroy the views
@ -837,7 +837,7 @@ export class Nav implements NavOutlet {
private removeView(view: ViewController) {
assert(
view.state === ViewState.Attached || view.state === ViewState.Destroyed,
view.state === VIEW_STATE_ATTACHED || view.state === VIEW_STATE_DESTROYED,
'view state should be loaded or destroyed'
);
@ -873,7 +873,7 @@ export class Nav implements NavOutlet {
if (i > activeViewIndex) {
// this view comes after the active view
// let's unload it
lifecycle(element, ViewLifecycle.WillUnload);
lifecycle(element, LIFECYCLE_WILL_UNLOAD);
this.destroyView(view);
} else if (i < activeViewIndex) {
// this view comes before the active view