{"action":"created","issue":{"url":"https://api.github.com/repos/heroku/react-refetch/issues/76","repository_url":"https://api.github.com/repos/heroku/react-refetch","labels_url":"https://api.github.com/repos/heroku/react-refetch/issues/76/labels{/name}","comments_url":"https://api.github.com/repos/heroku/react-refetch/issues/76/comments","events_url":"https://api.github.com/repos/heroku/react-refetch/issues/76/events","html_url":"https://github.com/heroku/react-refetch/pull/76","id":138663240,"number":76,"title":"Add option to specify fetch implementation","user":{"login":"passcod","id":155787,"avatar_url":"https://avatars.githubusercontent.com/u/155787?v=3","gravatar_id":"","url":"https://api.github.com/users/passcod","html_url":"https://github.com/passcod","followers_url":"https://api.github.com/users/passcod/followers","following_url":"https://api.github.com/users/passcod/following{/other_user}","gists_url":"https://api.github.com/users/passcod/gists{/gist_id}","starred_url":"https://api.github.com/users/passcod/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/passcod/subscriptions","organizations_url":"https://api.github.com/users/passcod/orgs","repos_url":"https://api.github.com/users/passcod/repos","events_url":"https://api.github.com/users/passcod/events{/privacy}","received_events_url":"https://api.github.com/users/passcod/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/heroku/react-refetch/labels/WIP/DO%20NOT%20MERGE","name":"WIP/DO NOT MERGE","color":"fbca04"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":45,"created_at":"2016-03-05T09:15:03Z","updated_at":"2016-03-09T22:31:27Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/heroku/react-refetch/pulls/76","html_url":"https://github.com/heroku/react-refetch/pull/76","diff_url":"https://github.com/heroku/react-refetch/pull/76.diff","patch_url":"https://github.com/heroku/react-refetch/pull/76.patch"},"body":"PR for #75.\r\n\r\nI think that covers it, it's a pretty simple feature :) The core focus of this PR works, and perfectly: one can now override the fetch implementation on a `connect` call basis. But details remain:\r\n\r\nI'm not sure about the chaining configuration API. To be exact: I like the API, but I'm not too happy about how I implemented it, but that's what feedback is for, right? The way it works is it preserves the existing options hash so the implementation is simple, but provides the chaining API on top. The way I did the chaining means you can only use a single `.with*` to set the relevant option:\r\n\r\n```js\r\n// Possible due to the implementation, but discouraged:\r\n@connect({\r\n  usersFetch: '/example'\r\n}, { withFetch: fetch })\r\nclass Foo extends Component {}\r\n\r\n// Chaining (recommended for public use):\r\n@connect.withFetch(fetch)({ ... })\r\nclass Foo extends Component {}\r\n\r\n// Multiple chaining (doesn't work with current PR):\r\n@connect.withFetch(fetch).withRef()({ ... })\r\nclass Foo extends Component {}\r\n\r\n// \"Detached\" style (functionally the same thing)\r\nconst refetch = connect.withFetch(fetch).withRef()\r\n\r\n@refetch({ ... })\r\nclass Foo extends Component {}\r\n```\r\n\r\nI have (as you can see above) added the `withFetch` option chainer. If you think that is best done in future work detached from this PR, I will remove it.\r\n\r\nI have added a test for this. I have _not_, however, changed the rest of the tests around to use `withFetch` to do dependency injection instead of overwriting `window.fetch`, which is something @ryanbrainard [mentioned](https://github.com/heroku/react-refetch/issues/75#issuecomment-192032812) as a potential outcome of this PR.\r\n\r\nI have modified the `wrappedInstance` exception message to mention using `.withFetch()` instead of `{ withFetch: true }`. I should probably revert that? (As it may be a breaking change, and not particularly necessary to do in this PR.)\r\n\r\nReally, the only thing bugging me about this is the chaining option impl. If someone has an idea on how to better do it…"},"comment":{"url":"https://api.github.com/repos/heroku/react-refetch/issues/comments/194542891","html_url":"https://github.com/heroku/react-refetch/pull/76#issuecomment-194542891","issue_url":"https://api.github.com/repos/heroku/react-refetch/issues/76","id":194542891,"user":{"login":"ryanbrainard","id":966764,"avatar_url":"https://avatars.githubusercontent.com/u/966764?v=3","gravatar_id":"","url":"https://api.github.com/users/ryanbrainard","html_url":"https://github.com/ryanbrainard","followers_url":"https://api.github.com/users/ryanbrainard/followers","following_url":"https://api.github.com/users/ryanbrainard/following{/other_user}","gists_url":"https://api.github.com/users/ryanbrainard/gists{/gist_id}","starred_url":"https://api.github.com/users/ryanbrainard/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ryanbrainard/subscriptions","organizations_url":"https://api.github.com/users/ryanbrainard/orgs","repos_url":"https://api.github.com/users/ryanbrainard/repos","events_url":"https://api.github.com/users/ryanbrainard/events{/privacy}","received_events_url":"https://api.github.com/users/ryanbrainard/received_events","type":"User","site_admin":false},"created_at":"2016-03-09T22:31:27Z","updated_at":"2016-03-09T22:31:27Z","body":"@passcod We could, but that would more methods for every option. I could be getting ahead of myself here, but I'm thinking is something like this where `buildRequest`, `fetch`, and `handleResponse` are just options in the mappings like everything else AND any option in the mapping can be set in a default. Something like this (notice the connect-level and mapping-level `handleResponse`s):\r\n\r\n```jsx\r\nconnect.defaults({\r\n  buildRequest: ...,\r\n  fetch: ...,\r\n  handleResponse: ...,\r\n  refreshing: true,\r\n  headers: {\r\n    'Custom-Header': 'true'\r\n  }\r\n}).(({ params: { userId } }) => ({\r\n    userFetch:    `/users/${userId}`,\r\n    likesStatusesFetch: {\r\n      url: `/users/${userId}/likes`,\r\n      handleResponse: ...\r\n    }\r\n}))(Profile)\r\n```\r\n\r\nThis example looks a bit ugly, but if these things were extracted out, I think the overall API work and is quite nice. Again, I could be getting ahead of myself here and blowing out the scope of this PR (sorry!), but I at least wanted to get your thoughts on this, and if we like it, can iterate toward it."}}