refactor(router): remove rootNode function
This commit is contained in:
parent
9ff6b0828f
commit
99f7404d8b
@ -1,5 +1,5 @@
|
|||||||
import { UrlTree, UrlSegment, equalUrlSegments } from './url_tree';
|
import { UrlTree, UrlSegment, equalUrlSegments } from './url_tree';
|
||||||
import { TreeNode, rootNode } from './utils/tree';
|
import { TreeNode } from './utils/tree';
|
||||||
import { forEach, shallowEqual } from './utils/collection';
|
import { forEach, shallowEqual } from './utils/collection';
|
||||||
import { RouterState, ActivatedRoute } from './router_state';
|
import { RouterState, ActivatedRoute } from './router_state';
|
||||||
import { Params, PRIMARY_OUTLET } from './shared';
|
import { Params, PRIMARY_OUTLET } from './shared';
|
||||||
@ -7,7 +7,7 @@ import { Params, PRIMARY_OUTLET } from './shared';
|
|||||||
export function createUrlTree(route: ActivatedRoute, urlTree: UrlTree, commands: any[],
|
export function createUrlTree(route: ActivatedRoute, urlTree: UrlTree, commands: any[],
|
||||||
queryParameters: Params | undefined, fragment: string | undefined): UrlTree {
|
queryParameters: Params | undefined, fragment: string | undefined): UrlTree {
|
||||||
if (commands.length === 0) {
|
if (commands.length === 0) {
|
||||||
return tree(rootNode(urlTree), urlTree, queryParameters, fragment);
|
return tree(urlTree._root, urlTree, queryParameters, fragment);
|
||||||
}
|
}
|
||||||
|
|
||||||
const normalizedCommands = normalizeCommands(commands);
|
const normalizedCommands = normalizeCommands(commands);
|
||||||
@ -19,7 +19,7 @@ export function createUrlTree(route: ActivatedRoute, urlTree: UrlTree, commands:
|
|||||||
const updated = normalizedCommands.commands.length > 0 ?
|
const updated = normalizedCommands.commands.length > 0 ?
|
||||||
updateMany(startingNode.children.slice(0), normalizedCommands.commands) :
|
updateMany(startingNode.children.slice(0), normalizedCommands.commands) :
|
||||||
[];
|
[];
|
||||||
const newRoot = constructNewTree(rootNode(urlTree), startingNode, updated);
|
const newRoot = constructNewTree(urlTree._root, startingNode, updated);
|
||||||
|
|
||||||
return tree(newRoot, urlTree, queryParameters, fragment);
|
return tree(newRoot, urlTree, queryParameters, fragment);
|
||||||
}
|
}
|
||||||
@ -87,11 +87,11 @@ function normalizeCommands(commands: any[]): NormalizedNavigationCommands {
|
|||||||
function findStartingNode(normalizedChange: NormalizedNavigationCommands, urlTree: UrlTree,
|
function findStartingNode(normalizedChange: NormalizedNavigationCommands, urlTree: UrlTree,
|
||||||
route: ActivatedRoute): TreeNode<UrlSegment> {
|
route: ActivatedRoute): TreeNode<UrlSegment> {
|
||||||
if (normalizedChange.isAbsolute) {
|
if (normalizedChange.isAbsolute) {
|
||||||
return rootNode(urlTree);
|
return urlTree._root;
|
||||||
} else {
|
} else {
|
||||||
const urlSegment =
|
const urlSegment =
|
||||||
findUrlSegment(route, urlTree, normalizedChange.numberOfDoubleDots);
|
findUrlSegment(route, urlTree, normalizedChange.numberOfDoubleDots);
|
||||||
return findMatchingNode(urlSegment, rootNode(urlTree));
|
return findMatchingNode(urlSegment, urlTree._root);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { UrlTree, UrlSegment } from './url_tree';
|
import { UrlTree, UrlSegment } from './url_tree';
|
||||||
import { PRIMARY_OUTLET } from './shared';
|
import { PRIMARY_OUTLET } from './shared';
|
||||||
import { rootNode, TreeNode } from './utils/tree';
|
import { TreeNode } from './utils/tree';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines a way to serialize/deserialize a url tree.
|
* Defines a way to serialize/deserialize a url tree.
|
||||||
@ -27,7 +27,7 @@ export class DefaultUrlSerializer implements UrlSerializer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
serialize(tree: UrlTree): string {
|
serialize(tree: UrlTree): string {
|
||||||
const node = serializeUrlTreeNode(rootNode(tree));
|
const node = serializeUrlTreeNode(tree._root);
|
||||||
const query = serializeQueryParams(tree.queryParameters);
|
const query = serializeQueryParams(tree.queryParameters);
|
||||||
const fragment = tree.fragment !== null ? `#${tree.fragment}` : '';
|
const fragment = tree.fragment !== null ? `#${tree.fragment}` : '';
|
||||||
return `${node}${query}${fragment}`;
|
return `${node}${query}${fragment}`;
|
||||||
|
@ -34,10 +34,6 @@ export class Tree<T> {
|
|||||||
contains(tree: Tree<T>): boolean { return contains(this._root, tree._root); }
|
contains(tree: Tree<T>): boolean { return contains(this._root, tree._root); }
|
||||||
}
|
}
|
||||||
|
|
||||||
export function rootNode<T>(tree: Tree<T>): TreeNode<T> {
|
|
||||||
return tree._root;
|
|
||||||
}
|
|
||||||
|
|
||||||
function findNode<T>(expected: T, c: TreeNode<T>): TreeNode<T> | null {
|
function findNode<T>(expected: T, c: TreeNode<T>): TreeNode<T> | null {
|
||||||
if (expected === c.value) return c;
|
if (expected === c.value) return c;
|
||||||
for (let cc of c.children) {
|
for (let cc of c.children) {
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"experimentalDecorators": true,
|
"experimentalDecorators": true,
|
||||||
"emitDecoratorMetadata": true,
|
"emitDecoratorMetadata": true,
|
||||||
|
"noEmitOnError": false,
|
||||||
"module": "commonjs",
|
"module": "commonjs",
|
||||||
"target": "es5",
|
"target": "es5",
|
||||||
"noImplicitAny": false,
|
"noImplicitAny": false,
|
||||||
@ -16,6 +17,8 @@
|
|||||||
"src/index.ts",
|
"src/index.ts",
|
||||||
"src/router.ts",
|
"src/router.ts",
|
||||||
"src/recognize.ts",
|
"src/recognize.ts",
|
||||||
|
"src/resolve.ts",
|
||||||
|
"src/create_router_state.ts",
|
||||||
"src/router.ts",
|
"src/router.ts",
|
||||||
"src/config.ts",
|
"src/config.ts",
|
||||||
"src/router_outlet_map.ts",
|
"src/router_outlet_map.ts",
|
||||||
@ -32,6 +35,7 @@
|
|||||||
"test/utils/tree.spec.ts",
|
"test/utils/tree.spec.ts",
|
||||||
"test/url_serializer.spec.ts",
|
"test/url_serializer.spec.ts",
|
||||||
"test/recognize.spec.ts",
|
"test/recognize.spec.ts",
|
||||||
|
"test/create_router_state.spec.ts",
|
||||||
"test/create_url_tree.spec.ts",
|
"test/create_url_tree.spec.ts",
|
||||||
"test/router.spec.ts",
|
"test/router.spec.ts",
|
||||||
"typings/index.d.ts"
|
"typings/index.d.ts"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user