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

Improve fetch #6155

Merged
merged 1 commit into from
Jun 13, 2019
Merged

Improve fetch #6155

merged 1 commit into from
Jun 13, 2019

Conversation

wycats
Copy link
Member

@wycats wycats commented Jun 10, 2019

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 😄

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.
Copy link
Member

@rwjblue rwjblue left a 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.

Copy link
Member Author

@wycats wycats left a 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.

Sure. That's why we separated into a different commit :)

@wycats
Copy link
Member Author

wycats commented Jun 10, 2019

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?'
Copy link
Member

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?'
Copy link
Member

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?

Copy link
Member Author

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.

@runspired
Copy link
Contributor

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?

@rwjblue
Copy link
Member

rwjblue commented Jun 11, 2019

@runspired AFAIK, no one is stubbing an ES module. Pretender does self.fetch = fakeFetch, which isn't related to stubbing an ES module (its stubbing a global though).

@runspired runspired merged commit cf399b2 into master Jun 13, 2019
@runspired runspired deleted the improve-fetch branch June 13, 2019 00:02
pete-the-pete pushed a commit to pete-the-pete/data that referenced this pull request Jul 23, 2019
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants