feat(router): add support for lazily loaded modules

This commit is contained in:
vsavkin
2016-07-06 11:02:16 -07:00
parent 6fcf962fb5
commit 8ebb8e44c8
13 changed files with 431 additions and 140 deletions

View File

@ -6,6 +6,14 @@
* found in the LICENSE file at https://angular.io/license
*/
import 'rxjs/add/operator/concatAll';
import 'rxjs/add/operator/last';
import {Observable} from 'rxjs/Observable';
import {of } from 'rxjs/observable/of';
import {PRIMARY_OUTLET} from '../shared';
export function shallowEqualArrays(a: any[], b: any[]): boolean {
if (a.length !== b.length) return false;
for (let i = 0; i < a.length; ++i) {
@ -77,4 +85,34 @@ export function forEach<K, V>(
callback(map[prop], prop);
}
}
}
export function waitForMap<A, B>(
obj: {[k: string]: A}, fn: (k: string, a: A) => Observable<B>): Observable<{[k: string]: B}> {
const waitFor: Observable<B>[] = [];
const res: {[k: string]: B} = {};
forEach(obj, (a: A, k: string) => {
if (k === PRIMARY_OUTLET) {
waitFor.push(fn(k, a).map((_: B) => {
res[k] = _;
return _;
}));
}
});
forEach(obj, (a: A, k: string) => {
if (k !== PRIMARY_OUTLET) {
waitFor.push(fn(k, a).map((_: B) => {
res[k] = _;
return _;
}));
}
});
if (waitFor.length > 0) {
return of (...waitFor).concatAll().last().map((last) => res);
} else {
return of (res);
}
}