-
Notifications
You must be signed in to change notification settings - Fork 28
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
Bind this.onError for XHR requests in TurboGraft.Remote #119
Conversation
@@ -33,7 +33,7 @@ class TurboGraft.Remote | |||
triggerEventFor 'turbograft:remote:start', @initiator, | |||
xhr: xhr | |||
|
|||
xhr.addEventListener 'error', @onError | |||
xhr.addEventListener 'error', @onError.bind(@) |
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.
can you do .bind(this)
?
Looks like it might address a lot of #118 cc @Shopify/tnt |
e9949a5
to
56e6fe7
Compare
By the looks of things, the |
@@ -33,7 +33,7 @@ class TurboGraft.Remote | |||
triggerEventFor 'turbograft:remote:start', @initiator, | |||
xhr: xhr | |||
|
|||
xhr.addEventListener 'error', @onError | |||
xhr.addEventListener 'error', @onError.bind(this) |
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.
More CoffeeScript-ey solution is to use =>
in the method definition (which binds the method in the constructor).
e0e9fe6
to
e6120ed
Compare
e6120ed
to
3fdf980
Compare
@@ -116,7 +116,7 @@ class TurboGraft.Remote | |||
enabledInputs.push(input) | |||
enabledInputs | |||
|
|||
onSuccess: (ev) -> | |||
onSuccess: (ev) => |
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.
Figured I'd switch this to a fat arrow too seen as it's always used as a callback
@qq99 & @lemonmade - round 2 please 😁 |
httpRequestType: "POST" | ||
httpUrl: "/foo/bar" | ||
refreshOnError: "foo" | ||
fail: done |
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.
If this never failed, would this test just timeout? Might be worth adding the success case that throws a meaningful error.
Just going back to look at dafb3a7#diff-58f1b55d4025fab95951247202574f55L156 to analyze some more... Looks like previously, @davidcornu LGTM let me know when you'd like me to 🎩 this against core |
Yeah that was my conclusion. |
@qq99 should be good to go. LMK if you want any help with 🎩 . |
Tested it in a few scenarios (order actions, some 422s) and looks good 🎩 |
🚢 |
I have a feeling this is causing https://bugsnag.com/shopify/shopify-js/errors/5666f3c78f2356495b6fe53f?filters%5Bevent.since%5D%5B%5D=30d.
r @qq99
cc @arapehl