Created
December 29, 2018 16:24
-
-
Save nathan-lapinski/01807112a5508c3a3fbff8d975aec475 to your computer and use it in GitHub Desktop.
createNode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createNode( | |
routeReuseStrategy: RouteReuseStrategy, curr: TreeNode<ActivatedRouteSnapshot>, | |
prevState?: TreeNode<ActivatedRoute>): TreeNode<ActivatedRoute> { | |
// reuse an activated route that is currently displayed on the screen | |
if (prevState && routeReuseStrategy.shouldReuseRoute(curr.value, prevState.value.snapshot)) { | |
const value = prevState.value; | |
value._futureSnapshot = curr.value; | |
const children = createOrReuseChildren(routeReuseStrategy, curr, prevState); | |
return new TreeNode<ActivatedRoute>(value, children); | |
// 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) { | |
const tree: TreeNode<ActivatedRoute> = detachedRouteHandle.route; | |
setFutureSnapshotsOfActivatedRoutes(curr, tree); | |
return tree; | |
} else { | |
const value = createActivatedRoute(curr.value); | |
const children = curr.children.map(c => createNode(routeReuseStrategy, c)); | |
return new TreeNode<ActivatedRoute>(value, children); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment