Guest User

Untitled

a guest
Apr 23rd, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. const { beforeMethod } = require("kaop-ts");
  2.  
  3. const Log = meta => {
  4. console.log(meta.key)
  5. console.log(meta.scope)
  6. console.log(meta.args)
  7. }
  8.  
  9. function applyToAll(advice) {
  10. return function applyAll(target) {
  11. const wove = beforeMethod(advice);
  12. for (let key in target.prototype) {
  13. Object.defineProperty(target.prototype, key,
  14. wove(target, key, Object.getOwnPropertyDescriptor(target.prototype, key)));
  15. }
  16. }
  17.  
  18. }
  19.  
  20. const track = applyToAll(Log)
  21.  
  22. @track
  23. class YourService {
  24. method1(num, str) {
  25.  
  26. }
  27. method2(num, str) {
  28.  
  29. }
  30. method3(num, str) {
  31.  
  32. }
  33. method4(num, str) {
  34.  
  35. }
  36. }
  37.  
  38. const b = new YourService;
  39. const a = new YourService;
  40.  
  41. b.method1(1, 123)
  42. a.method2("asdas", 131231)
  43. a.method4({asd: 1}, 131231)
Add Comment
Please, Sign In to add comment