Last active
January 2, 2019 18:37
-
-
Save SebastianHGonzalez/26230a55c91f5c10c33e591ec27a8b6b to your computer and use it in GitHub Desktop.
first approach to implemet point cuts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PointCut { | |
constructor(definition) { | |
this.inject(definition); | |
} | |
inject(definition) { | |
this.injectAspectToObjectMethods(definition.class.prototype); | |
} | |
injectAspectToObjectMethods(prototype) { | |
prototype[name] = this.decorate(prototype[name]); | |
} | |
decorate(joinPoint) { | |
const pointCut = this; | |
return function (...args) { | |
const context = this; | |
pointCut.before(context, joinPoint.name, ...args); | |
const result = pointCut.around(context, joinPoint, ...args); | |
pointCut.after(context, joinPoint.name, result, ...args); | |
return result; | |
} | |
} | |
before(context, joinPointName, ...args) { | |
console.log("before"); | |
} | |
after(context, joinPointName, result, ...args) { | |
console.log("after"); | |
} | |
around(context, joinPoint, ...args) { | |
console.log("around: start"); | |
const result = joinPoint.apply(context, args); | |
console.log("around: end"); | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment