Skip to content

Commit

Permalink
fix: allow woven of hierarchical structure
Browse files Browse the repository at this point in the history
Fix #53
  • Loading branch information
mgechev committed Mar 2, 2018
1 parent c9b4345 commit be529e3
Show file tree
Hide file tree
Showing 8 changed files with 620 additions and 15 deletions.
6 changes: 2 additions & 4 deletions demo/index.ts
Expand Up @@ -21,8 +21,7 @@ class CacheAspect {
})
before(meta: Metadata) {
console.log(
`Inside CacheAspect.before for ${meta.className}.${meta.method
.name} with args ${meta.method.args.join(', ')}`
`Inside CacheAspect.before for ${meta.className}.${meta.method.name} with args ${meta.method.args.join(', ')}`
);
}
@afterMethod({
Expand All @@ -35,8 +34,7 @@ class CacheAspect {
})
after(meta: Metadata) {
console.log(
`Inside CacheAspect.after for ${meta.className}.${meta.method
.name} with args ${meta.method.args.join(', ')}`
`Inside CacheAspect.after for ${meta.className}.${meta.method.name} with args ${meta.method.args.join(', ')}`
);
}
}
Expand Down
10 changes: 2 additions & 8 deletions lib/src/core/pointcut.ts
Expand Up @@ -3,20 +3,14 @@ import { Advice } from './advice';

export class Pointcut {
public jointPoints: JointPoint[];

public advice: Advice;

private _applications = new Set<Function>();

public apply(fn: Function, woveMetadata: any) {
if (this._applications.has(fn)) {
return;
} else {
this._applications.add(fn);
}
this.jointPoints.forEach(jp => {
let matches = jp.match(fn);
jp.wove({ fn, matches, woveMetadata }, this.advice);
});
this._applications.add(fn);
this.jointPoints.forEach(jp => jp.wove({ fn, matches: jp.match(fn), woveMetadata }, this.advice));
}
}
2 changes: 1 addition & 1 deletion lib/src/core/wove.ts
@@ -1,7 +1,7 @@
import { AspectRegistry, Targets } from './aspect';

export function weave<TFunction extends Function>(target: TFunction, config?: any): TFunction {
if ((target as any).__woven__) {
if (target.hasOwnProperty('__woven__')) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/joint_points/method_call.ts
Expand Up @@ -23,7 +23,7 @@ export class MethodCallJointPoint extends JointPoint {
if (
this.precondition.assert({
classDefinition: target,
methodName: key,
methodName: key
}) &&
typeof descriptor.value === 'function'
) {
Expand Down

0 comments on commit be529e3

Please sign in to comment.