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

Fix `m.request`/`m.jsonp` to not mutate arguments, simplify code #2288

Merged
merged 2 commits into from Nov 29, 2018

Conversation

3 participants
@isiahmeadows
Copy link
Collaborator

isiahmeadows commented Nov 9, 2018

Description

I basically recast it to remove 99% of the duplication. They're basically the same function mod how they fire their requests and append query parameters.

This also fixes the methods to be invoked with the expected this value, the options object, rather than this === undefined, which isn't documented.

Motivation and Context

#2254 stalled and I'd rather not pile yet another hack onto an already messy implementation. This does basically that, but better. I also saved 50 bytes min+gzip with my cleanup.

How Has This Been Tested?

Ran the tests as usual. I had to add a global for the mock, though - for some reason, we aren't testing FormData. (I didn't get around to actually adding new tests for it, though.)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation change

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • I have updated docs/change-log.md

@project-bot project-bot bot added this to Needs triage in Triage/bugs Nov 9, 2018

@isiahmeadows isiahmeadows force-pushed the isiahmeadows:request-fix branch from b29f3ae to a06f5e8 Nov 9, 2018

@isiahmeadows isiahmeadows moved this from Needs triage to High priority in Triage/bugs Nov 9, 2018

@isiahmeadows isiahmeadows requested a review from MithrilJS/collaborators Nov 9, 2018

Fix `m.request`/`m.jsonp` to not mutate arguments, simplify code
I basically recast it to remove 99% of the duplication. They're
basically the same function mod how they fire their requests and append
query parameters.

@isiahmeadows isiahmeadows force-pushed the isiahmeadows:request-fix branch from a06f5e8 to ec5672d Nov 9, 2018

@isiahmeadows isiahmeadows added the bug label Nov 14, 2018

@barneycarroll
Copy link
Member

barneycarroll left a comment

Nice one @isiahmeadows

@isiahmeadows isiahmeadows merged commit 7cbc15e into MithrilJS:next Nov 29, 2018

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

Triage/bugs automation moved this from High priority to Closed Nov 29, 2018

@isiahmeadows isiahmeadows deleted the isiahmeadows:request-fix branch Nov 29, 2018

@isiahmeadows isiahmeadows referenced this pull request Dec 6, 2018

Closed

Update request.js #2254

@qgustavor

This comment has been minimized.

Copy link

qgustavor commented Dec 6, 2018

This commit broke this code:

m.request({
  url: '/some-example-url',
  responseType: 'arraybuffer',
  extract: xhr => xhr.response
})

This line is trying to read xhr.responseText even when args.extract is defined. Trying to read it throws a DOMException as it's not accessible when xhr.responseType is not '' or 'text'.

@isiahmeadows

This comment has been minimized.

Copy link
Collaborator

isiahmeadows commented Dec 6, 2018

@qgustavor Please file a new issue with that bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment