X Tutup
The Wayback Machine - https://web.archive.org/web/20201201154819/https://github.com/developit/unfetch/pull/132
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

refactor response create function outside of promise handler #132

Open
wants to merge 6 commits into
base: master
from

Conversation

@kalisjoshua
Copy link

@kalisjoshua kalisjoshua commented Feb 14, 2020

not sure that this is favorable or not but thought that it might be and it allows
for easier testing of the creation of responses and their properties.

@developit
Copy link
Owner

@developit developit commented Feb 18, 2020

This will depend on the size impact - I've updated the repo to include a size check, we'll see what it nets.

@developit
Copy link
Owner

@developit developit commented Feb 18, 2020

Ah - it looks like this adds a named export to the actual unfetch package, which means it won't work - folks using CommonJS will have to do import('unfetch').default which is a breaking change.

Instead, if we could retrofit your work here into proper support for the Response interface, that would definitely be a justifiable export! It would be a nice step towards supporting Headers, Request and Response, something that's been on my todo list for ages.

@developit developit self-requested a review Feb 18, 2020
@kalisjoshua
Copy link
Author

@kalisjoshua kalisjoshua commented Feb 18, 2020

Filename Size Change
dist/unfetch.es.js 553 B +47 B (8%) 🔍
dist/unfetch.js 548 B +43 B (7%) 🔍
dist/unfetch.umd.js 627 B +49 B (7%) 🔍
@developit
Copy link
Owner

@developit developit commented Feb 18, 2020

@kalisjoshua that'll be the added export. One quick solution to check this would be to move the response function into a separate file (src/lib/response.mjs) that is imported by src/index.mjs and tests, that way it's not exported as unfetch.response.

kalisjoshua added 2 commits Feb 14, 2020
not sure that this is favorable or not but thought that it might be and it allows
for easier testing of the creation of responses and their properties.
@kalisjoshua kalisjoshua force-pushed the kalisjoshua:refactor-and-tests branch from 1477655 to ac63b91 Feb 18, 2020
@kalisjoshua
Copy link
Author

@kalisjoshua kalisjoshua commented Feb 18, 2020

This is done now.

@kalisjoshua that'll be the added export. One quick solution to check this would be to move the response function into a separate file (src/lib/response.mjs) that is imported by src/index.mjs and tests, that way it's not exported as unfetch.response.

I will look into the Response interface compatibility.

@kalisjoshua
Copy link
Author

@kalisjoshua kalisjoshua commented Feb 18, 2020

Filename Size Change
dist/unfetch.es.js 544 B +38 B (6%) 🔍
dist/unfetch.js 543 B +38 B (6%) 🔍
dist/unfetch.umd.js 617 B +39 B (6%) 🔍
@developit
Copy link
Owner

@developit developit commented Feb 19, 2020

Interesting that the numbers are still so increased. My guess is that's because we're ending up with a closure around the two top-level functions, whereas currently there is no closure required since all functionality exists within the single unfetch(){} function (as a sort of wrapper + implementation). Perhaps that's just something that we'll be giving up.

developit and others added 3 commits Feb 19, 2020
@kalisjoshua
Copy link
Author

@kalisjoshua kalisjoshua commented Feb 19, 2020

It's interesting to look at the compiled output diff of dist/unfetch.js between the master branch and my branch. On the master branch the for loop is expanded a little but on my branch the loop is most of the body of the function. I'm still examining it to see if there is anything that can be done to bring the output sizes closer because there isn't an extra closure.

@kalisjoshua
Copy link
Author

@kalisjoshua kalisjoshua commented Feb 19, 2020

I think the biggest contributor to the bloat that I created is because of the lifting of the response function out of the scope necessitating that arguments be passed in and that also results in a more complicated clone attribute on the response object. I am able to slim the output size a slight bit; encapsulated in the most recent commit.

@kalisjoshua kalisjoshua force-pushed the kalisjoshua:refactor-and-tests branch from 673f183 to 3986993 Feb 19, 2020
@kalisjoshua
Copy link
Author

@kalisjoshua kalisjoshua commented Feb 19, 2020

Filename Size Change
dist/unfetch.es.js 534 B +23 B (4%)
dist/unfetch.js 534 B +24 B (4%)
dist/unfetch.umd.js 605 B +23 B (3%)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.
X Tutup