refactor(router): misc refactoring (#13330)

This commit is contained in:
Victor Berchet
2016-12-09 10:44:46 -08:00
parent c8c1f22f9c
commit c0b001a6af
13 changed files with 217 additions and 411 deletions

View File

@ -60,7 +60,7 @@ export function last<T>(a: T[]): T {
}
export function and(bools: boolean[]): boolean {
return bools.reduce((a, b) => a && b, true);
return !bools.some(v => !v);
}
export function merge<V>(m1: {[key: string]: V}, m2: {[key: string]: V}): {[key: string]: V} {
@ -81,8 +81,7 @@ export function merge<V>(m1: {[key: string]: V}, m2: {[key: string]: V}): {[key:
return m;
}
export function forEach<K, V>(
map: {[key: string]: V}, callback: /*(V, K) => void*/ Function): void {
export function forEach<K, V>(map: {[key: string]: V}, callback: (v: V, k: string) => void): void {
for (const prop in map) {
if (map.hasOwnProperty(prop)) {
callback(map[prop], prop);
@ -117,9 +116,9 @@ export function waitForMap<A, B>(
const concatted$ = concatAll.call(of (...waitFor));
const last$ = l.last.call(concatted$);
return map.call(last$, () => res);
} else {
return of (res);
}
return of (res);
}
export function andObservables(observables: Observable<Observable<any>>): Observable<boolean> {
@ -130,9 +129,11 @@ export function andObservables(observables: Observable<Observable<any>>): Observ
export function wrapIntoObservable<T>(value: T | Promise<T>| Observable<T>): Observable<T> {
if (value instanceof Observable) {
return value;
} else if (value instanceof Promise) {
return fromPromise(value);
} else {
return of (value);
}
if (value instanceof Promise) {
return fromPromise(value);
}
return of (value);
}