-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Why AdvicePool, adviceMetadata, IMetadata are not exported from kaop-ts? #89
Comments
Thanks @kailashthakuri You're using an outdated API, please refer to the docs https://github.com/k1r0s/kaop-ts/blob/master/docs/api.md#how-do-i-define-an-advice You no longer need to import AdvicePool, adviceMetadata, etc May I know where did you find that code snippet? need to update it |
@kailashthakuri try this code snippet const { beforeMethod } = require(".");
const yourAdvice = meta => {
console.log(meta.target)
console.log(meta.args)
}
class YourService {
@beforeMethod(yourAdvice)
static someMethod(num, str) {
}
}
YourService.someMethod(1, "asdasd"); |
Thanks, But I just want to track which component and method get called for event tracking. I don't want to send parameter to my advice. i am trying to implement AOP in angular5. I want to intercept the method called and keep log for event tracking purpose. |
mmm okay, try this out: 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(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) |
Thanks a lot. (k1r0s) I edited your comment to put syntax highlight export class SigninComponent implements OnInit {
constructor(private store: Store<fromApp.AppState>, private eventTrackingService: EventTrackingService) { }
ngOnInit() {
}
@log()
submitForm(form: NgForm) {
let userName = form.value.userName;
let password = form.value.password;
this.store.dispatch(new AuthActions.trySignin({ username: userName, password: password }));
}
}
log.service.ts
import { beforeMethod } from "kaop-ts";
export const log = () => beforeMethod(meta => {
console.log("Method Name : "+ meta.key);
console.log("Class : "+ meta.target);
}) Here how can i get component Name? meta.target is not returning component name. |
https://github.com/k1r0s/kaop-ts/blob/master/docs/api.md#metadata as pointed in the docs:
@kailashthakuri going to close this since questions are out of issue's scope. Thanks! |
I have installed kaop-ts. Is there any other dependencies or package i have to install along with kaop-ts?
The text was updated successfully, but these errors were encountered: