Skip to content

Commit

Permalink
fix(router): parent resolve should complete before merging resolved data
Browse files Browse the repository at this point in the history
  • Loading branch information
vsavkin committed Oct 5, 2016
1 parent cf269d9 commit de0c9cf
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion modules/@angular/router/src/router.ts
Expand Up @@ -13,6 +13,7 @@ import {Subject} from 'rxjs/Subject';
import {Subscription} from 'rxjs/Subscription';
import {from} from 'rxjs/observable/from';
import {of } from 'rxjs/observable/of';
import {concatMap} from 'rxjs/operator/concatMap';
import {every} from 'rxjs/operator/every';
import {map} from 'rxjs/operator/map';
import {mergeAll} from 'rxjs/operator/mergeAll';
Expand Down Expand Up @@ -692,7 +693,7 @@ export class PreActivation {
resolveData(): Observable<any> {
if (this.checks.length === 0) return of (null);
const checks$ = from(this.checks);
const runningChecks$ = mergeMap.call(checks$, (s: any) => {
const runningChecks$ = concatMap.call(checks$, (s: any) => {
if (s instanceof CanActivate) {
return this.runResolve(s.route);
} else {
Expand Down
1 change: 1 addition & 0 deletions modules/@angular/router/test/integration.spec.ts
Expand Up @@ -577,6 +577,7 @@ describe('Integration', () => {
TestBed.configureTestingModule({
providers: [
{provide: 'resolveTwo', useValue: (a: any, b: any) => 2},
{provide: 'resolvePromiseTwo', useValue: (a: any, b: any) => Promise.resolve(2)},
{provide: 'resolveFour', useValue: (a: any, b: any) => 4},
{provide: 'resolveSix', useClass: ResolveSix}
]
Expand Down
17 changes: 17 additions & 0 deletions modules/@angular/router/test/router.spec.ts
Expand Up @@ -48,6 +48,23 @@ describe('Router', () => {
});
});

it('should wait for the parent resolve to complete', () => {
const parentResolve = new InheritedResolve(InheritedResolve.empty, {data: 'resolver'});
const childResolve = new InheritedResolve(parentResolve, {});

const parent = createActivatedRouteSnapshot('a', {resolve: parentResolve});
const child = createActivatedRouteSnapshot('b', {resolve: childResolve});

const s = new RouterStateSnapshot(
'url', new TreeNode(empty.root, [new TreeNode(parent, [new TreeNode(child, [])])]));

const inj = {get: (token: any) => () => Promise.resolve(`${token}_value`)};

checkResolveData(s, empty, inj, () => {
expect(s.root.firstChild.firstChild.data).toEqual({data: 'resolver_value'});
});
});

it('should copy over data when creating a snapshot', () => {
const r1 = new InheritedResolve(InheritedResolve.empty, {data: 'resolver1'});
const r2 = new InheritedResolve(InheritedResolve.empty, {data: 'resolver2'});
Expand Down

0 comments on commit de0c9cf

Please sign in to comment.