-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Improve fetch #6155
Improve fetch #6155
Conversation
1. Don't ever assign the internal `fetch` to `null`. Instead, throw immediately if fetch is not found. 2. Don't extract the global fetch into module state. Instead, export a function that looks up the global fetch each time. This allows libraries that mock `fetch` to do so after Ember Data has already been loaded.
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.
Could you roll back the todo
related changes? As far as I can tell they are unrelated to fixing the fetch
issue, and they will cause the test suite to fail because testem
does not support using QUnit.todo
's.
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.
Could you roll back the
todo
related changes? As far as I can tell they are unrelated to fixing thefetch
issue, and they will cause the test suite to fail becausetestem
does not support usingQUnit.todo
's.
Sure. That's why we separated into a different commit :)
Done. |
_fetch = () => fetch; | ||
} else { | ||
throw new Error( | ||
'cannot find the `fetch` module or the `fetch` global. Did you mean to install the `ember-fetch` addon?' |
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.
Nice touch, thank you for adding this!
return fetchFunction(options.url, options); | ||
} else { | ||
throw new Error( | ||
'cannot find the `fetch` module or the `fetch` global. Did you mean to install the `ember-fetch` addon?' |
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.
Do we need the same error in both places? What does that buy us?
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.
I wasn't sure which of the two we should do. At first glance, I'd prefer it to happen at the top level.
I could be misremembering but isn't stubbing ES modules in this way not possible in native and only possible due to an artifact of transpilation? If so, are we sure we want to encourage this pattern vs finding another way to provide the ability to stub? |
@runspired AFAIK, no one is stubbing an ES module. Pretender does |
1. Don't ever assign the internal `fetch` to `null`. Instead, throw immediately if fetch is not found. 2. Don't extract the global fetch into module state. Instead, export a function that looks up the global fetch each time. This allows libraries that mock `fetch` to do so after Ember Data has already been loaded.
We're not sure how to test this change. We'd welcome any advice 😄 (@rwjblue?)
We also added some errors for the situation where
fetch
could not be found as a module or on the global. We weren't sure where people would prefer to put this error (and whether it would be a problem to throw during module evaluation). We're open to any feedback on this 😄