refactor(router): rename queryParameters into queryParams

This commit is contained in:
vsavkin 2016-06-06 16:34:48 -07:00
parent 33b518ad21
commit ed50e17e5b
8 changed files with 22 additions and 22 deletions

View File

@ -5,14 +5,14 @@ import { RouterState, ActivatedRoute } from './router_state';
import { Params, PRIMARY_OUTLET } from './shared'; 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 { queryParams: Params | undefined, fragment: string | undefined): UrlTree {
if (commands.length === 0) { if (commands.length === 0) {
return tree(urlTree._root, urlTree, queryParameters, fragment); return tree(urlTree._root, urlTree, queryParams, fragment);
} }
const normalizedCommands = normalizeCommands(commands); const normalizedCommands = normalizeCommands(commands);
if (navigateToRoot(normalizedCommands)) { if (navigateToRoot(normalizedCommands)) {
return tree(new TreeNode<UrlSegment>(urlTree.root, []), urlTree, queryParameters, fragment); return tree(new TreeNode<UrlSegment>(urlTree.root, []), urlTree, queryParams, fragment);
} }
const startingNode = findStartingNode(normalizedCommands, urlTree, route); const startingNode = findStartingNode(normalizedCommands, urlTree, route);
@ -21,11 +21,11 @@ export function createUrlTree(route: ActivatedRoute, urlTree: UrlTree, commands:
[]; [];
const newRoot = constructNewTree(urlTree._root, startingNode, updated); const newRoot = constructNewTree(urlTree._root, startingNode, updated);
return tree(newRoot, urlTree, queryParameters, fragment); return tree(newRoot, urlTree, queryParams, fragment);
} }
function tree(root: TreeNode<UrlSegment>, urlTree: UrlTree, queryParameters: Params | undefined, fragment: string | undefined): UrlTree { function tree(root: TreeNode<UrlSegment>, urlTree: UrlTree, queryParams: Params | undefined, fragment: string | undefined): UrlTree {
const q = queryParameters ? stringify(queryParameters) : urlTree.queryParameters; const q = queryParams ? stringify(queryParams) : urlTree.queryParams;
const f = fragment ? fragment : urlTree.fragment; const f = fragment ? fragment : urlTree.fragment;
return new UrlTree(root, q, f); return new UrlTree(root, q, f);
} }

View File

@ -67,7 +67,7 @@ export class RouterLink implements OnChanges {
if (!(typeof this.target === "string") || this.target == '_self') { if (!(typeof this.target === "string") || this.target == '_self') {
this.router.navigate(this.commands, { this.router.navigate(this.commands, {
relativeTo: this.route, relativeTo: this.route,
queryParameters: this.queryParams, queryParams: this.queryParams,
fragment: this.fragment fragment: this.fragment
}); });
return false; return false;
@ -78,7 +78,7 @@ export class RouterLink implements OnChanges {
private updateTargetUrlAndHref(): void { private updateTargetUrlAndHref(): void {
const tree = this.router.createUrlTree(this.commands, { const tree = this.router.createUrlTree(this.commands, {
relativeTo: this.route, relativeTo: this.route,
queryParameters: this.queryParams, queryParams: this.queryParams,
fragment: this.fragment fragment: this.fragment
}); });
if (tree) { if (tree) {

View File

@ -13,7 +13,7 @@ export function recognize(rootComponentType: Type, config: RouterConfig, url: Ur
try { try {
const match = new MatchResult(rootComponentType, config, [url.root], {}, url._root.children, [], PRIMARY_OUTLET, null, url.root); const match = new MatchResult(rootComponentType, config, [url.root], {}, url._root.children, [], PRIMARY_OUTLET, null, url.root);
const roots = constructActivatedRoute(match); const roots = constructActivatedRoute(match);
const res = new RouterStateSnapshot(roots[0], url.queryParameters, url.fragment); const res = new RouterStateSnapshot(roots[0], url.queryParams, url.fragment);
return new Observable<RouterStateSnapshot>(obs => { return new Observable<RouterStateSnapshot>(obs => {
obs.next(res); obs.next(res);
obs.complete(); obs.complete();

View File

@ -24,7 +24,7 @@ import 'rxjs/add/operator/concatMap';
import {of} from 'rxjs/observable/of'; import {of} from 'rxjs/observable/of';
import {forkJoin} from 'rxjs/observable/forkJoin'; import {forkJoin} from 'rxjs/observable/forkJoin';
export interface NavigationExtras { relativeTo?: ActivatedRoute; queryParameters?: Params; fragment?: string; } export interface NavigationExtras { relativeTo?: ActivatedRoute; queryParams?: Params; fragment?: string; }
/** /**
* An event triggered when a navigation starts * An event triggered when a navigation starts
@ -169,9 +169,9 @@ export class Router {
* router.createUrlTree(['../../team/44/user/22'], {relativeTo: route}); * router.createUrlTree(['../../team/44/user/22'], {relativeTo: route});
* ``` * ```
*/ */
createUrlTree(commands: any[], {relativeTo, queryParameters, fragment}: NavigationExtras = {}): UrlTree { createUrlTree(commands: any[], {relativeTo, queryParams, fragment}: NavigationExtras = {}): UrlTree {
const a = relativeTo ? relativeTo : this.routerState.root; const a = relativeTo ? relativeTo : this.routerState.root;
return createUrlTree(a, this.currentUrlTree, commands, queryParameters, fragment); return createUrlTree(a, this.currentUrlTree, commands, queryParams, fragment);
} }

View File

@ -28,7 +28,7 @@ export class DefaultUrlSerializer implements UrlSerializer {
serialize(tree: UrlTree): string { serialize(tree: UrlTree): string {
const node = serializeUrlTreeNode(tree._root); const node = serializeUrlTreeNode(tree._root);
const query = serializeQueryParams(tree.queryParameters); const query = serializeQueryParams(tree.queryParams);
const fragment = tree.fragment !== null ? `#${tree.fragment}` : ''; const fragment = tree.fragment !== null ? `#${tree.fragment}` : '';
return `${node}${query}${fragment}`; return `${node}${query}${fragment}`;
} }

View File

@ -13,7 +13,7 @@ export class UrlTree extends Tree<UrlSegment> {
/** /**
* @internal * @internal
*/ */
constructor(root: TreeNode<UrlSegment>, public queryParameters: {[key: string]: string}, public fragment: string | null) { constructor(root: TreeNode<UrlSegment>, public queryParams: {[key: string]: string}, public fragment: string | null) {
super(root); super(root);
} }
} }

View File

@ -143,19 +143,19 @@ describe('createUrlTree', () => {
it("should set query params", () => { it("should set query params", () => {
const p = serializer.parse("/"); const p = serializer.parse("/");
const t = create(p.root, p, [], {a: 'hey'}); const t = create(p.root, p, [], {a: 'hey'});
expect(t.queryParameters).toEqual({a: 'hey'}); expect(t.queryParams).toEqual({a: 'hey'});
}); });
it("should stringify query params", () => { it("should stringify query params", () => {
const p = serializer.parse("/"); const p = serializer.parse("/");
const t = create(p.root, p, [], <any>{a: 1}); const t = create(p.root, p, [], <any>{a: 1});
expect(t.queryParameters).toEqual({a: '1'}); expect(t.queryParams).toEqual({a: '1'});
}); });
it("should reuse old query params when given undefined", () => { it("should reuse old query params when given undefined", () => {
const p = serializer.parse("/?a=1"); const p = serializer.parse("/?a=1");
const t = create(p.root, p, [], undefined); const t = create(p.root, p, [], undefined);
expect(t.queryParameters).toEqual({a: '1'}); expect(t.queryParams).toEqual({a: '1'});
}); });
it("should set fragment", () => { it("should set fragment", () => {
@ -171,12 +171,12 @@ describe('createUrlTree', () => {
}); });
}); });
function create(start: UrlSegment | null, tree: UrlTree, commands: any[], queryParameters?: Params, fragment?: string) { function create(start: UrlSegment | null, tree: UrlTree, commands: any[], queryParams?: Params, fragment?: string) {
if (!start) { if (!start) {
expect(start).toBeDefined(); expect(start).toBeDefined();
} }
const s = new ActivatedRouteSnapshot([], <any>{}, PRIMARY_OUTLET, "someComponent", null, <any>start); const s = new ActivatedRouteSnapshot([], <any>{}, PRIMARY_OUTLET, "someComponent", null, <any>start);
const a = new ActivatedRoute(new BehaviorSubject(null), new BehaviorSubject(null), PRIMARY_OUTLET, "someComponent", s); const a = new ActivatedRoute(new BehaviorSubject(null), new BehaviorSubject(null), PRIMARY_OUTLET, "someComponent", s);
advanceActivatedRoute(a); advanceActivatedRoute(a);
return createUrlTree(a, tree, commands, queryParameters, fragment); return createUrlTree(a, tree, commands, queryParams, fragment);
} }

View File

@ -86,12 +86,12 @@ describe('url serializer', () => {
it("should parse query params", () => { it("should parse query params", () => {
const tree = url.parse("/one?a=1&b=2"); const tree = url.parse("/one?a=1&b=2");
expect(tree.queryParameters).toEqual({a: '1', b: '2'}); expect(tree.queryParams).toEqual({a: '1', b: '2'});
}); });
it("should parse key only query params", () => { it("should parse key only query params", () => {
const tree = url.parse("/one?a"); const tree = url.parse("/one?a");
expect(tree.queryParameters).toEqual({a: 'true'}); expect(tree.queryParams).toEqual({a: 'true'});
}); });
it("should serializer query params", () => { it("should serializer query params", () => {