feat(router): add support for lazily loaded modules
This commit is contained in:
@ -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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user