Skip to content
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

Decorated method returns nothing #8

Closed
Ledzz opened this issue Jul 30, 2019 · 2 comments · Fixed by #9
Closed

Decorated method returns nothing #8

Ledzz opened this issue Jul 30, 2019 · 2 comments · Fixed by #9

Comments

@Ledzz
Copy link

Ledzz commented Jul 30, 2019

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Feature request
[ ] Documentation issue or request

Current behavior

Method decorated with @measure returns nothing. Haven't tested with other decorators.

Expected behavior

Returned value does not change

Minimal reproduction of the problem with instructions

https://stackblitz.com/edit/typescript-okyls9

@NetanelBasal
Copy link
Owner

The issue is here:

  descriptor.value = function(...args) {
    const start = performance.now();
    originalMethod.apply(this, args);
    const end = performance.now();
    console.log(`Call to ${propertyKey} took ${(end - start).toFixed(2)} milliseconds.`);
  };

It should be:

  descriptor.value = function(...args) {
    const start = performance.now();
    const result = originalMethod.apply(this, args);
    const end = performance.now();
    console.log(`Call to ${propertyKey} took ${(end - start).toFixed(2)} milliseconds.`);
    return result;
  };

Do you want to create a PR?

@Ledzz
Copy link
Author

Ledzz commented Jul 30, 2019

yes, I'll do it today :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants