Created
April 16, 2018 09:26
-
-
Save k1r0s/fdefdcd7753dc3de53a8cc37422c7ae9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| const { beforeMethod } = require("kaop-ts"); | |
| const Log = meta => { | |
| console.log(meta.key) | |
| console.log(meta.scope) | |
| console.log(meta.args) | |
| } | |
| function applyToAll(advice) { | |
| return function applyAll(target) { | |
| const wove = beforeMethod(advice); | |
| for (let key in target.prototype) { | |
| Object.defineProperty(target.prototype, key, | |
| wove(target, key, Object.getOwnPropertyDescriptor(target.prototype, key))); | |
| } | |
| } | |
| } | |
| const track = applyToAll(Log) | |
| @track | |
| class YourService { | |
| method1(num, str) { | |
| } | |
| method2(num, str) { | |
| } | |
| method3(num, str) { | |
| } | |
| method4(num, str) { | |
| } | |
| } | |
| const b = new YourService; | |
| const a = new YourService; | |
| b.method1(1, 123) | |
| a.method2("asdas", 131231) | |
| a.method4({asd: 1}, 131231) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment