refactor(nav): create NavControllerBase and public abstract class

Use NavController as the public API, and NavControllerBase as the
internal API. Refactored all app/nav/tabs unit tests and created
centralized mocking functions.
This commit is contained in:
Adam Bradley
2016-07-15 15:54:56 -05:00
parent 5909fa4ba5
commit 0a7d865975
17 changed files with 3384 additions and 3307 deletions

View File

@ -1,28 +1,35 @@
import { Directive, Input, Optional } from '@angular/core';
import { Directive, HostListener, Input, Optional } from '@angular/core';
import { NavController } from './nav-controller';
import { noop } from '../../util/util';
/**
* @name NavPush
* @description
* Directive for declaratively linking to a new page instead of using
* {@link ../NavController/#push NavController.push}. Similar to ui-router's `ui-sref`.
* Directive to declaratively push a new page to the current nav
* stack.
*
* @usage
* ```html
* <button [navPush]="pushPage"></button>
* ```
* To specify parameters you can use array syntax or the `nav-params` property:
*
* To specify parameters you can use array syntax or the `navParams`
* property:
*
* ```html
* <button [navPush]="pushPage" [navParams]="params"></button>
* <button [navPush]="pushPage" [navParams]="params">Go</button>
* ```
* Where `pushPage` and `params` are specified in your component, and `pushPage`
* contains a reference to a [@Page component](../../../config/Page/):
*
* Where `pushPage` and `params` are specified in your component,
* and `pushPage` contains a reference to a
* [@Page component](../../../config/Page/):
*
* ```ts
* import {LoginPage} from 'login';
* import { LoginPage } from './login';
*
* @Component({
* template: `<button [navPush]="pushPage" [navParams]="params"></button>`
* template: `<button [navPush]="pushPage" [navParams]="params">Go</button>`
* })
* class MyPage {
* constructor(){
@ -32,61 +39,42 @@ import { NavController } from './nav-controller';
* }
* ```
*
* ### Alternate syntax
* You can also use syntax similar to Angular2's router, passing an array to
* NavPush:
* ```html
* <button [navPush]="[pushPage, params]"></button>
* ```
* @demo /docs/v2/demos/navigation/
* @see {@link /docs/v2/components#navigation Navigation Component Docs}
* @see {@link ../NavPop NavPop API Docs}
*
*/
@Directive({
selector: '[navPush]',
host: {
'(click)': 'onClick()',
'role': 'link'
}
selector: '[navPush]'
})
export class NavPush {
/**
* @input {Page} the page you want to push
*/
@Input() navPush: any;
/**
* @input {any} Any parameters you want to pass along
*/
@Input() navParams: any;
constructor(
@Optional() private _nav: NavController
) {
if (!_nav) {
console.error('nav-push must be within a NavController');
}
}
/**
* @private
* @input {Page} The Page to push onto the Nav.
*/
onClick() {
let destination: any, params: any;
@Input() navPush: any[]|string;
if (this.navPush instanceof Array) {
if (this.navPush.length > 2) {
throw 'Too many [navPush] arguments, expects [View, { params }]';
}
destination = this.navPush[0];
params = this.navPush[1] || this.navParams;
/**
* @input {any} Parameters to pass to the page.
*/
@Input() navParams: {[k: string]: any};
} else {
destination = this.navPush;
params = this.navParams;
constructor(@Optional() private _nav: NavController) {
if (!_nav) {
console.error('navPush must be within a NavController');
}
}
@HostListener('click')
onClick(): boolean {
// If no target, or if target is _self, prevent default browser behavior
if (this._nav) {
this._nav.push(this.navPush, this.navParams, noop);
return false;
}
this._nav && this._nav.push(destination, params);
return true;
}
}