Skip to content

Commit

Permalink
fix(angular): proxies
Browse files Browse the repository at this point in the history
  • Loading branch information
manucorporat committed Mar 30, 2018
1 parent cece447 commit 2308239
Show file tree
Hide file tree
Showing 7 changed files with 276 additions and 74 deletions.
2 changes: 1 addition & 1 deletion angular/src/directives/proxies-list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const DIRECTIVES = [
d.Menu,
d.MenuButton,
d.MenuToggle,
d.NavControllerBase,
d.Nav,
d.NavPop,
d.NavPush,
d.NavSetRoot,
Expand Down
295 changes: 253 additions & 42 deletions angular/src/directives/proxies.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion angular/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const DECLARATIONS = [
d.Menu,
d.MenuButton,
d.MenuToggle,
d.NavControllerBase,
d.Nav,
d.NavPop,
d.NavPush,
d.NavSetRoot,
Expand Down
3 changes: 3 additions & 0 deletions angular/test/nav/.angular-cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,8 @@
"defaults": {
"styleExt": "scss",
"component": {}
},
"warnings": {
"typescriptMismatch": false
}
}
10 changes: 5 additions & 5 deletions core/src/components/nav/nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import mdTransitionAnimation from './animations/md.transition';
@Component({
tag: 'ion-nav',
})
export class NavControllerBase implements NavOutlet {
export class Nav implements NavOutlet {

private _init = false;
private _queue: TransitionInstruction[] = [];
Expand Down Expand Up @@ -470,7 +470,7 @@ export class NavControllerBase implements NavOutlet {
for (let i = 0; i < viewControllers.length; i++) {
const view = viewControllers[i];
view.delegate = ti.opts.delegate;
const nav = view._nav;
const nav = view.nav;
if (nav && nav !== this) {
throw new Error('inserted view was already inserted');
}
Expand Down Expand Up @@ -663,13 +663,13 @@ export class NavControllerBase implements NavOutlet {
if (existingIndex > -1) {
// this view is already in the stack!!
// move it to its new location
assert(view._nav === this, 'view is not part of the nav');
assert(view.nav === this, 'view is not part of the nav');
this._views.splice(index, 0, this._views.splice(existingIndex, 1)[0]);
} else {
assert(!view._nav, 'nav is used');
assert(!view.nav, 'nav is used');
// this is a new view to add to the stack
// create the new entering view
view._setNav(this);
view.nav = this;

// insert the entering view into the correct index in the stack
this._views.splice(index, 0, view);
Expand Down
18 changes: 9 additions & 9 deletions core/src/components/nav/test/nav-controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { mockDocument, mockElement } from '@stencil/core/testing';
import { NavControllerBase } from '../nav';
import { Nav } from '../nav';
import { ViewController } from '../view-controller';
import { AnimationControllerImpl } from '../../animation-controller/animation-controller';
import { createConfigController } from '../../../global/config-controller';
Expand Down Expand Up @@ -345,8 +345,8 @@ describe('NavController', () => {
expect(nav.getByIndex(3).component).toEqual(MockView2);
expect(nav.getByIndex(4).component).toEqual(MockView3);

expect(nav.getByIndex(1)._nav).toEqual(nav);
expect(nav.getByIndex(2)._nav).toEqual(nav);
expect(nav.getByIndex(1).nav).toEqual(nav);
expect(nav.getByIndex(2).nav).toEqual(nav);

}, 10000);
});
Expand All @@ -357,7 +357,7 @@ describe('NavController', () => {
nav.pop(null, trnsDone).then(() => {
fail('it should not succeed');
done();
}).catch((err) => {
}).catch((err: any) => {
const hasCompleted = false;
const requiresTransition = false;
const rejectReason = new Error('no views in the stack to be removed');
Expand Down Expand Up @@ -1019,7 +1019,7 @@ describe('NavController', () => {
});


let nav: NavControllerBase;
let nav: Nav;

function spyOnLifecycles(view: ViewController) {
const element = view.element as any;
Expand Down Expand Up @@ -1091,15 +1091,15 @@ function mockView(component ?: any, data ?: any) {
return view;
}

function mockViews(nav: NavControllerBase, views: ViewController[]) {
function mockViews(nav: Nav, views: ViewController[]) {
nav['_views'] = views;
views.forEach(v => {
v._setNav(nav);
v.nav = nav;
});
}

function mockNavController(): NavControllerBase {
const nav = new NavControllerBase() as any;
function mockNavController(): Nav {
const nav = new Nav() as any;
nav.el = mockElement('ion-nav') as HTMLElement;
nav.ionNavChanged = {emit: function() { return; } };
nav.animationCtrl = new AnimationControllerImpl() as any;
Expand Down
20 changes: 4 additions & 16 deletions core/src/components/nav/view-controller.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@

import { NavOptions, ViewState } from './nav-util';
import { NavControllerBase } from './nav';
import { assert } from '../../utils/helpers';
import { FrameworkDelegate } from '../..';
import { FrameworkDelegate, Nav } from '../..';
import { attachComponent } from '../../utils/framework-delegate';

/**
Expand All @@ -27,7 +26,7 @@ export class ViewController {
private _cntDir: any;
private _leavingOpts: NavOptions;

_nav: NavControllerBase;
nav: Nav;
_state: ViewState = ViewState.New;

/** @hidden */
Expand All @@ -52,17 +51,6 @@ export class ViewController {
}
}

_setNav(navCtrl: NavControllerBase) {
this._nav = navCtrl;
}

/**
* @hidden
*/
getNav(): NavControllerBase {
return this._nav;
}

/**
* @hidden
*/
Expand Down Expand Up @@ -115,7 +103,7 @@ export class ViewController {
element.remove();
}
}
this._nav = this._cntDir = this._leavingOpts = null;
this.nav = this._cntDir = this._leavingOpts = null;
this._state = ViewState.Destroyed;
}

Expand All @@ -124,7 +112,7 @@ export class ViewController {
* @returns {number} Returns the index of this page within its `NavController`.
*/
get index(): number {
return (this._nav ? this._nav.indexOf(this) : -1);
return (this.nav ? this.nav.indexOf(this) : -1);
}
}

Expand Down

0 comments on commit 2308239

Please sign in to comment.