Skip to content

Commit f88823a

Browse files
committedApr 18, 2017
fix(navcontroller): lazy loading is queued
1 parent 5776f76 commit f88823a

File tree

17 files changed

+667
-589
lines changed

17 files changed

+667
-589
lines changed
 

‎scripts/gulp/tasks/test.ts

+4
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ function karmaTest(watch: boolean, done: Function) {
8585

8686
let karmaConfig = {
8787
configFile: join(SCRIPTS_ROOT, 'karma/karma.conf.js'),
88+
singleRun: true,
8889
};
8990

9091
if (watch) {
@@ -96,6 +97,9 @@ function karmaTest(watch: boolean, done: Function) {
9697
args: ['--grep', argv.testGrep]
9798
};
9899
}
100+
if (typeof argv.debug !== 'undefined') {
101+
karmaConfig.singleRun = false;
102+
}
99103

100104
new karma.Server(karmaConfig, done).start();
101105
}

‎scripts/karma/system.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000;
44

55
// disable console debugs/errors/warns from printing out
66
console.debug = () => {};
7-
console.error = () => {};
7+
// console.error = () => {};
88
console.warn = () => {};
99

1010
__karma__.loaded = function () {};

‎src/animations/animation.ts

+7
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,13 @@ export class Animation {
103103
return 0;
104104
}
105105

106+
/**
107+
* Returns if the animation is a root one.
108+
*/
109+
isRoot(): boolean {
110+
return !this.parent;
111+
}
112+
106113
/**
107114
* Set the duration for this animation.
108115
*/

‎src/components/app/test/app.spec.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,9 @@ describe('App', () => {
167167
expect(plt.exitApp).not.toHaveBeenCalled();
168168
done();
169169
}).catch((err: Error) => {
170+
fail(err);
170171
done(err);
171-
});
172+
});
172173
});
173174

174175
it('should pop the second view in the root nav', () => {

‎src/components/nav/test/basic/pages/first-page/first-page.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
</ion-item>
4343
<ion-item>
4444
<ion-label>Toggle Can Leave</ion-label>
45-
<ion-toggle (click)="canLeave = !canLeave"></ion-toggle>
45+
<ion-toggle [(ngModel)]="canLeave"></ion-toggle>
4646
</ion-item>
4747
<button ion-item (click)="viewDismiss()">View Dismiss</button>
4848
<button ion-item (click)="quickPush()">New push during transition</button>

‎src/components/nav/test/nav.spec.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ describe('Nav', () => {
3434
expect(nav.setPages).toHaveBeenCalledWith(knownViews, null, null);
3535
done();
3636
}).catch((err: Error) => {
37+
fail(err);
3738
done(err);
3839
});
3940
});
@@ -56,6 +57,7 @@ describe('Nav', () => {
5657
expect(nav.setPages).toHaveBeenCalledWith(knownViews, null, null);
5758
done();
5859
}).catch((err: Error) => {
60+
fail(err);
5961
done(err);
6062
});
6163
});
@@ -72,7 +74,8 @@ describe('Nav', () => {
7274
promise.then(() => {
7375
expect(nav.push).toHaveBeenCalled();
7476
done();
75-
}).catch((err: Error) => {
77+
}).catch((err: Error) => {
78+
fail(err);
7679
done(err);
7780
});
7881
});

‎src/components/tabs/tab.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ export class Tab extends NavControllerBase {
292292
/**
293293
* @hidden
294294
*/
295-
load(opts: NavOptions, done?: Function) {
295+
load(opts: NavOptions, done?: () => void) {
296296
if (!this._loaded && this.root) {
297297
this.setElementClass('show-tab', true);
298298
this.push(this.root, this.rootParams, opts, done);
@@ -305,7 +305,7 @@ export class Tab extends NavControllerBase {
305305
this._dom.read(() => {
306306
this.resize();
307307
});
308-
done(true);
308+
done();
309309
}
310310
}
311311

‎src/components/tabs/test/tabs.spec.ts

-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ describe('Tabs', () => {
162162
it('should get the tab', () => {
163163
var tabs = mockTabs();
164164
var tab0 = mockTab(tabs);
165-
tab0.setRoot(<any>{});
166165
var tab1 = mockTab(tabs);
167166

168167
expect(tabs.getIndex(tab0)).toEqual(0);

‎src/navigation/nav-controller-base.ts

+198-217
Large diffs are not rendered by default.

‎src/navigation/nav-util.ts

+15-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { NavControllerBase } from './nav-controller-base';
88
import { Transition } from '../transitions/transition';
99

1010

11-
export function getComponent(linker: DeepLinker, nameOrPageOrView: any, params?: any) {
11+
export function getComponent(linker: DeepLinker, nameOrPageOrView: any, params?: any): Promise<ViewController> {
1212
if (typeof nameOrPageOrView === 'function') {
1313
return Promise.resolve(
1414
new ViewController(nameOrPageOrView, params)
@@ -24,7 +24,7 @@ export function getComponent(linker: DeepLinker, nameOrPageOrView: any, params?:
2424
return Promise.resolve(null);
2525
}
2626

27-
export function convertToView(linker: DeepLinker, nameOrPageOrView: any, params: any) {
27+
export function convertToView(linker: DeepLinker, nameOrPageOrView: any, params: any): Promise<ViewController> {
2828
if (nameOrPageOrView) {
2929
if (isViewController(nameOrPageOrView)) {
3030
// is already a ViewController
@@ -34,11 +34,10 @@ export function convertToView(linker: DeepLinker, nameOrPageOrView: any, params:
3434
return getComponent(linker, nameOrPageOrView, params);
3535
}
3636

37-
console.error(`invalid page component: ${nameOrPageOrView}`);
3837
return Promise.resolve(null);
3938
}
4039

41-
export function convertToViews(linker: DeepLinker, pages: any[]) {
40+
export function convertToViews(linker: DeepLinker, pages: any[]): Promise<ViewController[]> {
4241
const views: Promise<ViewController>[] = [];
4342
if (isArray(pages)) {
4443
for (var i = 0; i < pages.length; i++) {
@@ -147,6 +146,14 @@ export interface NavLink {
147146
defaultHistory?: any[];
148147
}
149148

149+
export interface NavResult {
150+
hasCompleted: boolean;
151+
requiresTransition: boolean;
152+
enteringName?: string;
153+
leavingName?: string;
154+
direction?: string;
155+
}
156+
150157
export interface NavSegment {
151158
id: string;
152159
name: string;
@@ -188,12 +195,13 @@ export interface TransitionRejectFn {
188195
export interface TransitionInstruction {
189196
opts: NavOptions;
190197
insertStart?: number;
191-
insertViews?: ViewController[];
198+
insertViews?: any[];
192199
removeView?: ViewController;
193200
removeStart?: number;
194201
removeCount?: number;
195-
resolve?: TransitionResolveFn;
196-
reject?: TransitionRejectFn;
202+
resolve?: (hasCompleted: boolean) => void;
203+
reject?: (rejectReason: string) => void;
204+
done?: Function;
197205
leavingRequiresTransition?: boolean;
198206
enteringRequiresTransition?: boolean;
199207
requiresTransition?: boolean;

‎src/navigation/test/deep-linker.spec.ts

+1
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ describe('DeepLinker', () => {
284284
expect(result.length).toEqual(1);
285285
done();
286286
}).catch((err: Error) => {
287+
fail(err);
287288
done(err);
288289
});
289290
});

‎src/navigation/test/nav-controller.spec.ts

+406-339
Large diffs are not rendered by default.

‎src/navigation/test/overlay-proxy.spec.ts

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ describe('Overlay Proxy', () => {
1616
expect(instance.overlay.dismiss).toHaveBeenCalled();
1717
done();
1818
}).catch((err: Error) => {
19+
fail(err);
1920
done(err);
2021
});
2122
});
@@ -69,6 +70,7 @@ describe('Overlay Proxy', () => {
6970
expect(knownOverlay.onWillDismiss).toHaveBeenCalledWith(handler);
7071
done();
7172
}).catch((err: Error) => {
73+
fail(err);
7274
done(err);
7375
});
7476
});
@@ -91,6 +93,7 @@ describe('Overlay Proxy', () => {
9193
expect(deepLinker.getComponentFromName).not.toHaveBeenCalled();
9294
done();
9395
}).catch((err: Error) => {
96+
fail(err);
9497
done(err);
9598
});
9699
});
@@ -112,6 +115,7 @@ describe('Overlay Proxy', () => {
112115
expect(deepLinker.getComponentFromName).toHaveBeenCalledWith(componentName);
113116
done();
114117
}).catch((err: Error) => {
118+
fail(err);
115119
done(err);
116120
});
117121
});

‎src/navigation/view-controller.ts

+6-8
Original file line numberDiff line numberDiff line change
@@ -541,26 +541,24 @@ export class ViewController {
541541
/**
542542
* @hidden
543543
*/
544-
_lifecycleTest(lifecycle: string): boolean | Promise<any> {
544+
_lifecycleTest(lifecycle: string): Promise<any> {
545545
const instance = this.instance;
546546
const methodName = 'ionViewCan' + lifecycle;
547547
if (instance && instance[methodName]) {
548548
try {
549549
var result = instance[methodName]();
550-
if (result === false) {
551-
return false;
552-
} else if (result instanceof Promise) {
550+
if (result instanceof Promise) {
553551
return result;
554552
} else {
555-
return true;
553+
// Any value but explitic false, should be true
554+
return Promise.resolve(result !== false);
556555
}
557556

558557
} catch (e) {
559-
console.error(`${this.name} ${methodName} error: ${e.message}`);
560-
return false;
558+
return Promise.reject(`${this.name} ${methodName} error: ${e.message}`);
561559
}
562560
}
563-
return true;
561+
return Promise.resolve(true);
564562
}
565563

566564
_lifecycle(lifecycle: string) {

‎src/transitions/transition-controller.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ export class TransitionController {
2020
constructor(public plt: Platform, private _config: Config) {}
2121

2222
getRootTrnsId(nav: NavControllerBase): number {
23-
let parent = <NavControllerBase>nav.parent;
24-
while (parent) {
25-
if (isPresent(parent._trnsId)) {
26-
return parent._trnsId;
23+
nav = <NavControllerBase>nav.parent;
24+
while (nav) {
25+
if (isPresent(nav._trnsId)) {
26+
return nav._trnsId;
2727
}
28-
parent = parent.parent;
28+
nav = nav.parent;
2929
}
3030
return null;
3131
}

‎src/transitions/transition.ts

+9-5
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ export class Transition extends Animation {
2424
parent: Transition;
2525
trnsId: number;
2626

27-
constructor(plt: Platform, public enteringView: ViewController, public leavingView: ViewController, opts: AnimationOptions) {
27+
constructor(
28+
plt: Platform,
29+
public enteringView: ViewController,
30+
public leavingView: ViewController,
31+
opts: AnimationOptions
32+
) {
2833
super(plt, null, opts);
2934
}
3035

@@ -34,13 +39,12 @@ export class Transition extends Animation {
3439
this._trnsStart = trnsStart;
3540
}
3641

37-
isRoot(): boolean {
38-
return !this.parent;
39-
}
40-
4142
start() {
4243
this._trnsStart && this._trnsStart();
4344
this._trnsStart = null;
45+
46+
// bubble up start
47+
this.parent && this.parent.start();
4448
}
4549

4650
destroy() {

‎src/util/test/module-loader.spec.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ describe('module-loader', () => {
1919
promise.then((response) => {
2020
expect(ngModuleLoader.load).toHaveBeenCalledWith(pathPrefix, exportSuffix);
2121
}).catch((err: Error) => {
22-
done(err);
22+
fail(err);
23+
done(err);
2324
});
2425
});
2526

0 commit comments

Comments
 (0)
Please sign in to comment.