-
Notifications
You must be signed in to change notification settings - Fork 131
Return promise for decorator on async method #147
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
Conversation
tizmagik
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, and great work! This makes sense -- I just had a couple notes inline.
Thanks also for adding a test to trackingEventMethodDecorator.test.js -- would you mind also adding an e2e test with an async use case? I tend to put more weight behind that suite since it's actually testing the external API.
src/trackEventMethodDecorator.js
Outdated
| .then(() => { | ||
| return fn; | ||
| }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: mind rewriting as:
.then(() => fn)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed with d7adf1f
I also added an e2e test as suggested.
When writing the test, I noticed that the tracking function breaks if a promise is rejected. It will fail on { value } since value is set to null after reject. So when using the example in the readme:
@track((props, state, methodArgs, [{ value }, err]) => { } <-- will give TypeError
.catch(error => { trackEvent(null, error); throw error; }); <-- trackEventMethodDecorators.js line 28, value is set to null
So the happy flow is working now, but maybe this should be fixed as well. (changing null to {}?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea that makes sense, good catch! Mind making that change as a separate PR (will need an accompanying test update)
tizmagik
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this! (And apologies for the delay!)
|
Released as v7.3.0 -- thank you! 🎉 |
After updating from 5.3.0 my application broke on a method that was returned a promise. It turned out that the instead of the promise, undefined was returned by the method, comparable to the behaviour described in issue #106.
This has been fixed by adding
return fnintrackEventMethodDecorator.The unit test now has an extra check to see if the original method still works.