2016-06-08 14:13:41 -04:00
|
|
|
import {PRIMARY_OUTLET} from './shared';
|
|
|
|
import {shallowEqual} from './utils/collection';
|
|
|
|
import {Tree, TreeNode} from './utils/tree';
|
2016-06-09 17:11:54 -04:00
|
|
|
import {DefaultUrlSerializer, serializeSegment} from './url_serializer';
|
2016-05-26 19:50:59 -04:00
|
|
|
|
|
|
|
export function createEmptyUrlTree() {
|
2016-06-08 14:13:41 -04:00
|
|
|
return new UrlTree(
|
|
|
|
new TreeNode<UrlSegment>(new UrlSegment('', {}, PRIMARY_OUTLET), []), {}, null);
|
2016-05-26 19:50:59 -04:00
|
|
|
}
|
2016-05-21 20:35:55 -04:00
|
|
|
|
2016-05-24 16:41:37 -04:00
|
|
|
/**
|
|
|
|
* A URL in the tree form.
|
|
|
|
*/
|
2016-05-21 20:35:55 -04:00
|
|
|
export class UrlTree extends Tree<UrlSegment> {
|
2016-06-02 18:18:34 -04:00
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
*/
|
2016-06-08 14:13:41 -04:00
|
|
|
constructor(
|
|
|
|
root: TreeNode<UrlSegment>, public queryParams: {[key: string]: string},
|
|
|
|
public fragment: string|null) {
|
2016-05-21 20:35:55 -04:00
|
|
|
super(root);
|
|
|
|
}
|
2016-06-09 17:11:54 -04:00
|
|
|
|
|
|
|
toString(): string {
|
|
|
|
return new DefaultUrlSerializer().serialize(this);
|
|
|
|
}
|
2016-05-21 20:35:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export class UrlSegment {
|
2016-06-02 18:18:34 -04:00
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
*/
|
2016-06-08 14:13:41 -04:00
|
|
|
constructor(
|
|
|
|
public path: string, public parameters: {[key: string]: string}, public outlet: string) {}
|
2016-05-23 19:14:23 -04:00
|
|
|
|
2016-06-09 17:11:54 -04:00
|
|
|
toString(): string {
|
|
|
|
return serializeSegment(this);
|
2016-05-23 19:14:23 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function equalUrlSegments(a: UrlSegment[], b: UrlSegment[]): boolean {
|
|
|
|
if (a.length !== b.length) return false;
|
|
|
|
for (let i = 0; i < a.length; ++i) {
|
|
|
|
if (a[i].path !== b[i].path) return false;
|
|
|
|
if (!shallowEqual(a[i].parameters, b[i].parameters)) return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|