Skip to content

Commit

Permalink
refactor(router): determine if a route (and its subtree) should be re…
Browse files Browse the repository at this point in the history
…attached until detached route retrieving
  • Loading branch information
dmkuba committed May 4, 2019
1 parent 7d6f488 commit ae081b9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions packages/router/src/create_router_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ function createNode(

// retrieve an activated route that is used to be displayed, but is not currently displayed
} else {
const detachedRouteHandle =
<DetachedRouteHandleInternal>routeReuseStrategy.retrieve(curr.value);
if (detachedRouteHandle) {
if (routeReuseStrategy.shouldAttach(curr.value)) {
const detachedRouteHandle =
<DetachedRouteHandleInternal>routeReuseStrategy.retrieve(curr.value);
const tree: TreeNode<ActivatedRoute> = detachedRouteHandle.route;
setFutureSnapshotsOfActivatedRoutes(curr, tree);
return tree;
Expand Down
6 changes: 3 additions & 3 deletions packages/router/test/create_router_state.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,20 @@ describe('create router state', () => {
{path: 'a', component: ComponentA}, {path: 'b', component: ComponentB, outlet: 'left'},
{path: 'c', component: ComponentC, outlet: 'left'}
];
spyOn(reuseStrategy, 'retrieve').and.callThrough();
spyOn(reuseStrategy, 'shouldAttach').and.callThrough();

const prevState =
createRouterState(reuseStrategy, createState(config, 'a(left:b)'), emptyState());
advanceState(prevState);

// Expect 2 calls as the baseline setup
expect(reuseStrategy.retrieve).toHaveBeenCalledTimes(2);
expect(reuseStrategy.shouldAttach).toHaveBeenCalledTimes(2);

// This call should produce a reused activated route
const state = createRouterState(reuseStrategy, createState(config, 'a(left:c)'), prevState);

// Verify the retrieve method has been called one more time
expect(reuseStrategy.retrieve).toHaveBeenCalledTimes(3);
expect(reuseStrategy.shouldAttach).toHaveBeenCalledTimes(3);
});
});

Expand Down

0 comments on commit ae081b9

Please sign in to comment.