chore(router): clang-format

This commit is contained in:
vsavkin
2016-05-04 15:01:27 -07:00
parent abfb522f83
commit b30ddfbfc5
8 changed files with 108 additions and 75 deletions

View File

@ -1,4 +1,13 @@
import {RouteSegment, UrlSegment, Tree, TreeNode, rootNode, UrlTree, RouteTree, equalUrlSegments} from './segments';
import {
RouteSegment,
UrlSegment,
Tree,
TreeNode,
rootNode,
UrlTree,
RouteTree,
equalUrlSegments
} from './segments';
import {RoutesMetadata, RouteMetadata} from './metadata/metadata';
import {Type, isBlank, isPresent, stringify} from './facade/lang';
import {ListWrapper, StringMapWrapper} from './facade/collection';
@ -8,14 +17,16 @@ import {ComponentResolver} from '@angular/core';
import {DEFAULT_OUTLET_NAME} from './constants';
import {reflector} from '@angular/core';
export function recognize(componentResolver: ComponentResolver, rootComponent: Type,
url: UrlTree, existingTree: RouteTree): Promise<RouteTree> {
export function recognize(componentResolver: ComponentResolver, rootComponent: Type, url: UrlTree,
existingTree: RouteTree): Promise<RouteTree> {
let matched = new _MatchResult(rootComponent, [url.root], {}, rootNode(url).children, []);
return _constructSegment(componentResolver, matched, rootNode(existingTree)).then(roots => new RouteTree(roots[0]));
return _constructSegment(componentResolver, matched, rootNode(existingTree))
.then(roots => new RouteTree(roots[0]));
}
function _recognize(componentResolver: ComponentResolver, parentComponent: Type,
url: TreeNode<UrlSegment>, existingSegments: TreeNode<RouteSegment>[]): Promise<TreeNode<RouteSegment>[]> {
url: TreeNode<UrlSegment>,
existingSegments: TreeNode<RouteSegment>[]): Promise<TreeNode<RouteSegment>[]> {
let metadata = _readMetadata(parentComponent); // should read from the factory instead
if (isBlank(metadata)) {
throw new BaseException(
@ -30,29 +41,34 @@ function _recognize(componentResolver: ComponentResolver, parentComponent: Type,
}
let segmentsWithRightOutlet = existingSegments.filter(r => r.value.outlet == match.outlet);
let segmentWithRightOutlet = segmentsWithRightOutlet.length > 0 ? segmentsWithRightOutlet[0] : null;
let segmentWithRightOutlet =
segmentsWithRightOutlet.length > 0 ? segmentsWithRightOutlet[0] : null;
let main = _constructSegment(componentResolver, match, segmentWithRightOutlet);
let aux =
_recognizeMany(componentResolver, parentComponent, match.aux, existingSegments).then(_checkOutletNameUniqueness);
let aux = _recognizeMany(componentResolver, parentComponent, match.aux, existingSegments)
.then(_checkOutletNameUniqueness);
return PromiseWrapper.all([main, aux]).then(ListWrapper.flatten);
}
function _recognizeMany(componentResolver: ComponentResolver, parentComponent: Type,
urls: TreeNode<UrlSegment>[], existingSegments: TreeNode<RouteSegment>[]): Promise<TreeNode<RouteSegment>[]> {
let recognized = urls.map(u => _recognize(componentResolver, parentComponent, u, existingSegments));
function _recognizeMany(
componentResolver: ComponentResolver, parentComponent: Type, urls: TreeNode<UrlSegment>[],
existingSegments: TreeNode<RouteSegment>[]): Promise<TreeNode<RouteSegment>[]> {
let recognized =
urls.map(u => _recognize(componentResolver, parentComponent, u, existingSegments));
return PromiseWrapper.all(recognized).then(ListWrapper.flatten);
}
function _constructSegment(componentResolver: ComponentResolver,
matched: _MatchResult, existingSegment: TreeNode<RouteSegment>): Promise<TreeNode<RouteSegment>[]> {
function _constructSegment(
componentResolver: ComponentResolver, matched: _MatchResult,
existingSegment: TreeNode<RouteSegment>): Promise<TreeNode<RouteSegment>[]> {
return componentResolver.resolveComponent(matched.component)
.then(factory => {
let segment = _createOrReuseSegment(matched, factory, existingSegment);
let existingChildren = isPresent(existingSegment) ? existingSegment.children : [];
if (matched.leftOverUrl.length > 0) {
return _recognizeMany(componentResolver, factory.componentType, matched.leftOverUrl, existingChildren)
return _recognizeMany(componentResolver, factory.componentType, matched.leftOverUrl,
existingChildren)
.then(children => [new TreeNode<RouteSegment>(segment, children)]);
} else {
return _recognizeLeftOvers(componentResolver, factory.componentType, existingChildren)
@ -61,21 +77,23 @@ function _constructSegment(componentResolver: ComponentResolver,
});
}
function _createOrReuseSegment(matched: _MatchResult, factory: ComponentFactory<any>, segmentNode: TreeNode<RouteSegment>): RouteSegment {
function _createOrReuseSegment(matched: _MatchResult, factory: ComponentFactory<any>,
segmentNode: TreeNode<RouteSegment>): RouteSegment {
let segment = isPresent(segmentNode) ? segmentNode.value : null;
if (isPresent(segment) && equalUrlSegments(segment.urlSegments, matched.consumedUrlSegments)
&& StringMapWrapper.equals(segment.parameters, matched.parameters) &&
segment.outlet == matched.outlet && factory.componentType == segment.type) {
if (isPresent(segment) && equalUrlSegments(segment.urlSegments, matched.consumedUrlSegments) &&
StringMapWrapper.equals(segment.parameters, matched.parameters) &&
segment.outlet == matched.outlet && factory.componentType == segment.type) {
return segment;
} else {
return new RouteSegment(matched.consumedUrlSegments, matched.parameters, matched.outlet,
factory.componentType, factory);
factory.componentType, factory);
}
}
function _recognizeLeftOvers(componentResolver: ComponentResolver,
parentComponent: Type, existingSegments: TreeNode<RouteSegment>[]): Promise<TreeNode<RouteSegment>[]> {
function _recognizeLeftOvers(
componentResolver: ComponentResolver, parentComponent: Type,
existingSegments: TreeNode<RouteSegment>[]): Promise<TreeNode<RouteSegment>[]> {
return componentResolver.resolveComponent(parentComponent)
.then(factory => {
let metadata = _readMetadata(factory.componentType);
@ -87,14 +105,20 @@ function _recognizeLeftOvers(componentResolver: ComponentResolver,
if (r.length === 0) {
return PromiseWrapper.resolve([]);
} else {
let segmentsWithMatchingOutlet = existingSegments.filter(r => r.value.outlet == DEFAULT_OUTLET_NAME);
let segmentWithMatchingOutlet = segmentsWithMatchingOutlet.length > 0 ? segmentsWithMatchingOutlet[0] : null;
let existingChildren = isPresent(segmentWithMatchingOutlet) ? segmentWithMatchingOutlet.children : [];
let segmentsWithMatchingOutlet =
existingSegments.filter(r => r.value.outlet == DEFAULT_OUTLET_NAME);
let segmentWithMatchingOutlet =
segmentsWithMatchingOutlet.length > 0 ? segmentsWithMatchingOutlet[0] : null;
let existingChildren =
isPresent(segmentWithMatchingOutlet) ? segmentWithMatchingOutlet.children : [];
return _recognizeLeftOvers(componentResolver, r[0].component, existingChildren).then(children => {
return _recognizeLeftOvers(componentResolver, r[0].component, existingChildren)
.then(children => {
return componentResolver.resolveComponent(r[0].component)
.then(factory => {
let segment = _createOrReuseSegment(new _MatchResult(r[0].component, [], {}, [], []), factory, segmentWithMatchingOutlet);
let segment =
_createOrReuseSegment(new _MatchResult(r[0].component, [], {}, [], []),
factory, segmentWithMatchingOutlet);
return [new TreeNode<RouteSegment>(segment, children)];
});
});
@ -177,15 +201,14 @@ function _checkOutletNameUniqueness(nodes: TreeNode<RouteSegment>[]): TreeNode<R
}
class _MatchResult {
constructor(public component: Type|string, public consumedUrlSegments: UrlSegment[],
constructor(public component: Type | string, public consumedUrlSegments: UrlSegment[],
public parameters: {[key: string]: string},
public leftOverUrl: TreeNode<UrlSegment>[], public aux: TreeNode<UrlSegment>[]) {}
get outlet():string {
return this.consumedUrlSegments.length === 0 ||
isBlank(this.consumedUrlSegments[0].outlet) ?
DEFAULT_OUTLET_NAME :
this.consumedUrlSegments[0].outlet;
get outlet(): string {
return this.consumedUrlSegments.length === 0 || isBlank(this.consumedUrlSegments[0].outlet) ?
DEFAULT_OUTLET_NAME :
this.consumedUrlSegments[0].outlet;
}
}