Skip to content

Commit

Permalink
Merge pull request rangle#828 from stevenkampen/fix-dependency-tree-s…
Browse files Browse the repository at this point in the history
…upport-skipself

Fix dependency tree support skipself
  • Loading branch information
Steven Kampen authored Nov 30, 2016
2 parents fa0eec9 + 2d375f3 commit b12d680
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 19 deletions.
5 changes: 5 additions & 0 deletions src/backend/utils/description.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import {DebugElement} from '@angular/core';

export interface Dependency {
type: string;
decorators: Array<string>;
}

export interface Property {
key: string;
value;
Expand Down
8 changes: 4 additions & 4 deletions src/frontend/components/dependency/dependency.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*ngFor="let dep of dependencies">
<a href="#"
class="node-item-property"
(click)="onDependencySelected(dep)">
{{dep}}
(click)="onDependencySelected(dep.type)">
{{dep.type}}
</a>
</li>
</ul>
Expand Down Expand Up @@ -36,8 +36,8 @@
<li *ngFor="let dep of comp.dependencies">
<a href="#"
class="node-item-property"
(click)="onDependencySelected(dep)">
{{dep}}
(click)="onDependencySelected(dep.type)">
{{dep.type}}
</a>
</li>
</ul>
Expand Down
10 changes: 6 additions & 4 deletions src/frontend/components/dependency/dependency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class Dependency {

constructor(private userActions: UserActions) {}

private get dependencies(): Array<string> {
private get dependencies(): Array<{[key: string]: any}> {
if (this.selectedNode == null) {
return [];
}
Expand Down Expand Up @@ -83,9 +83,11 @@ export class Dependency {
const dependents = new Array<Node>();

this.tree.recurseAll(node => {
if (node.dependencies.indexOf(dependency) >= 0) {
dependents.push(node);
}
this.dependencies.map((dep: any) => {
if (dep.type === dependency) {
dependents.push(node);
}
});
});

return dependents;
Expand Down
20 changes: 13 additions & 7 deletions src/frontend/components/injector-tree/injector-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ export class InjectorTree implements OnChanges {
}

this.selectedNode.dependencies.forEach(
dependency => {
if (this.selectedNode.injectors.indexOf(dependency) < 0) {
(dependency: any) => {
if (this.selectedNode.injectors.indexOf(dependency.type) < 0) {
const parent = this.parseUtils.getDependencyLink
(this.tree, this.selectedNode.id, dependency);
(this.tree, this.selectedNode.id, dependency.type);
if (!parent) {
rootElement.injectors.push(dependency);
rootElement.injectors.push(dependency.type);
}
}
});
Expand Down Expand Up @@ -198,11 +198,17 @@ export class InjectorTree implements OnChanges {
this.graphUtils.addLine(this.svg, x1, y1, x2, y2, 'arrow stroke-component');
}

this.selectedNode.dependencies.forEach((dependency) => {
this.selectedNode.dependencies.forEach((dependency: any) => {
const providedForSelf = this.selectedNode.providers.reduce((prev, curr, idx, p) =>
prev ? prev : p[idx].key === dependency.type && dependency.decorators.indexOf('@SkipSelf') < 0, false);
if (providedForSelf) {
return;
}

const parent = this.parseUtils.getDependencyLink
(this.tree, this.selectedNode.id, dependency);
(this.tree, this.selectedNode.id, dependency.type);
if (parent) {
const service = positions[parent.id].injectors[dependency];
const service = positions[parent.id].injectors[dependency.type];
if (service) {
x1 = positions[this.selectedNode.id].x + 5;
y1 = positions[this.selectedNode.id].y - 10;
Expand Down
3 changes: 3 additions & 0 deletions src/tree/decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ export const propertyDecorators = (instance): Array<any> =>
export const parameterTypes = (instance): Array<any> =>
Reflect.getOwnMetadata('design:paramtypes', instance.constructor) || [];

export const injectedParameterDecorators = (instance): Array<any> =>
Reflect.getOwnMetadata('parameters', instance.constructor) || [];

export const iteratePropertyDecorators = (instance, fn: (key: string, decorator) => void) => {
if (instance == null) {
return;
Expand Down
4 changes: 2 additions & 2 deletions src/tree/node.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Property} from '../backend/utils/description';
import {Property, Dependency} from '../backend/utils/description';

export interface EventListener {
name: string;
Expand All @@ -20,7 +20,7 @@ export interface Node {
description: Array<Property>;
nativeElement: () => HTMLElement; // null on frontend
listeners: Array<EventListener>;
dependencies: Array<string>;
dependencies: Array<Dependency>;
directives: Array<string>;
injectors: Array<string>;
providers: Array<Property>;
Expand Down
11 changes: 9 additions & 2 deletions src/tree/transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as clone from 'clone';
import {
Description,
Property,
Dependency,
} from '../backend/utils/description';

import {
Expand All @@ -21,6 +22,7 @@ import {
componentOutputs,
parameterTypes,
propertyDecorators,
injectedParameterDecorators,
} from './decorators';

/// Transform a {@link DebugElement} or {@link DebugNode} element into a Node
Expand Down Expand Up @@ -192,9 +194,14 @@ const getChangeDetection = (metadata): number => {
}
};

const getDependencies = (instance): Array<string> => {
const getDependencies = (instance): Array<Dependency> => {
if (instance == null) {
return [];
}
return parameterTypes(instance).map(param => functionName(param));
const paramTypes = parameterTypes(instance);
const parameterDecorators = injectedParameterDecorators(instance);
return paramTypes.map((param, i) => ({
type: functionName(param),
decorators: parameterDecorators[i] ? parameterDecorators[i].map(d => d.toString()) : [],
}));
};

0 comments on commit b12d680

Please sign in to comment.