-
-
Notifications
You must be signed in to change notification settings - Fork 54
[Proposal] ic-ajax -> ember-fetch #19
Comments
Con: |
@jamesarosen that seems like a huge con |
Con: in those browsers where the real fetch is available, pretender won't intercept requests properly |
@cibernox similarly for Sinon and other |
this is both a CON and a PRO. Think other HTTP libs, typically they don't throw an exception if the response was 500, rather they give you an object with the status code. Rather they only fail if the connection itself failed, or if some code exploded. |
incorrect, ember-fetch never falls back to native. (although this may not be obvious) |
@stefanpenner why is it a success not rejecting 4xx or 5xx? Genuinely interested. |
|
@stefanpenner that seems like a very systemic change for Ember's model hook itself. As-is how would |
Well, I would think our current approach is slightly difficient. Most systems understand We can also provide Its also worth nothing that you wouldn't do (unless more conventions where baked into ember, which they could be). model() {
return fetch('something');
} rather, it would be: model() {
return fetch('something').then((response) => response.json());
} Which clearly starts to get verbose. One interesting thought to improve the fidelity, without exploding the verbosity (and somewhat inspired by rails strong-params) may results in extensions to fetch, to enable something like? model() {
return fetch('something').expect(200).asJSON()
} With maybe some sensible defaults if |
@stefanpenner I would want a wider range of failure states than just |
@bcardarella in all honestly, you actually want all the options. The strong convention in some cases, and in others you want full control. I suspect |
This is not clearly a good thing to me. The primary reason to adopt fetch is that this will be a standard and we can someday remove our custom implementation. If that is not the goal, then what is? |
It can be the goal, unfortunately only realistic if a polyfil can be of sufficient fidelity to reasonably be a drop-in replacement. Unfortunately, I do not believe that to be the case yet. some context. That being said, the polyfil should be more the sufficient for most use-cases, I believe GH itself uses it. Opting for the polyfil always does reduce 👣 🔫 's Once it is deemed safe, we can remove this aspect of |
Personally I'd like to see more real-world use cases of ember-fetch before we throw out ic-ajax as the default. I do think the fetch API is the future and the direction we should head in, but I also feel (based upon this thread) the implementation and impact to existing ember apps has not been fully thought through. If the intent of this RFC is to get fetch into ember-cli as the default in anticipation of the 1.0 landing sometime in the near future I don't feel confident that this will be as complete a solution as we should have. I can start migrating the DockYard client apps over to ember-fetch and we can help develop use cases. It would be nice if some other companies/shops can do the same. |
Sounds good, please do. Please note: I have been using it for some time, or I wouldn't have brought it up. |
If mocking libraries will continue to work and we can provide a simplistic convenience |
Stefan is looking for people to try this out and give feedback. We have enough Ember projects that we could contribute good information to this RFC and the spec. There isn't much risk to establishing this preference because it's being polyfilled so it will work wherever. The gain is that we will be able to provide valuable feedback to the ember community. Assuming this eventually get's merged we will also be ahead of the curve and not need to update existing apps to accomidate it. > What is ember-fetch? > > * a wrapper around: https://github.com/github/fetch > * which is a partial polyfil for https://fetch.spec.whatwg.org/ > * more info: https://github.com/stefanpenner/ember-fetch > * never falls back to native (so always works the same, and works with pretender) > > Why is this discussion happening now and not earlier? > > * ember 2 no longer supports IE8, and github/fetch is IE9+ > * fetch is a spec primitive of the DOM, it stands to reason we should prefer that over $.ajax > * maybe we can catch issues to help adapt/improve/add to the spec > * $.ajax is crazy quirky > * uploads have progress in the request object (unsure if the polifill does this or not actually, need to verify) > > Cons: > > * its not $.ajax which, although not a spec thing, is basically a primitive many devs are used to > * features like `$.ajaxPrefilter` are not obviously a thing in `fetch` (maybe some other approach ?) > * .... ? > > > Noop: > > * still no formal cancelation > > RFC: ember-cli/rfcs#19
I'm proposing this to thoughtbot to use on our future ember apps here: thoughtbot/guides#342 |
So, @mitchlloyd introduced me to using |
I think this is an astute point @stefanpenner is making here. From the vantage point of the client a 5xx error is resolved. It is the server telling you something went wrong. You can't just reach across the boundary of HTTP and expect to change state on the backend when a problem happens. HTTP is a stateless protocol after all. So it seems perfectly logical to me that it resolves in this scenario. Now the client has a few things it can do in this scenario:
I am in favor of using fetch. I can see why people might want |
Without a richer API (like @stefanpenner's suggested // 1: exceptions as flow-control:
model() {
return fetch('/something')
.then(function(response) {
if (response.status >= 400) { throw new Error("Whoops"); }
});
// 2: wrap in a promise:
model() {
return new Ember.RSVP.Promise(function(resolve, reject) {
fetch('/something')
.then(function(response) {
if (response.status >= 400) { reject("Whoops"); }
});
} I agree that giving the app author more control to do things like retry or use backup data is good. But |
Stefan is looking for people to try this out and give feedback. We have enough Ember projects that we could contribute good information to this RFC and the spec. There isn't much risk to establishing this preference because it's being polyfilled so it will work wherever. The gain is that we will be able to provide valuable feedback to the ember community. Assuming this eventually get's merged we will also be ahead of the curve and not need to update existing apps to accomidate it. > What is ember-fetch? > > * a wrapper around: https://github.com/github/fetch > * which is a partial polyfil for https://fetch.spec.whatwg.org/ > * more info: https://github.com/stefanpenner/ember-fetch > * never falls back to native (so always works the same, and works with pretender) > > Why is this discussion happening now and not earlier? > > * ember 2 no longer supports IE8, and github/fetch is IE9+ > * fetch is a spec primitive of the DOM, it stands to reason we should prefer that over $.ajax > * maybe we can catch issues to help adapt/improve/add to the spec > * $.ajax is crazy quirky > * uploads have progress in the request object (unsure if the polifill does this or not actually, need to verify) > > Cons: > > * its not $.ajax which, although not a spec thing, is basically a primitive many devs are used to > * features like `$.ajaxPrefilter` are not obviously a thing in `fetch` (maybe some other approach ?) > * .... ? > > > Noop: > > * still no formal cancelation > > RFC: ember-cli/rfcs#19
Stefan is looking for people to try this out and give feedback. We have enough Ember projects that we could contribute good information to this RFC and the spec. There isn't much risk to establishing this preference because it's being polyfilled so it will work wherever. The gain is that we will be able to provide valuable feedback to the ember community. Assuming this eventually get's merged we will also be ahead of the curve and not need to update existing apps to accomidate it. > What is ember-fetch? > > * a wrapper around: https://github.com/github/fetch > * which is a partial polyfil for https://fetch.spec.whatwg.org/ > * more info: https://github.com/stefanpenner/ember-fetch > * never falls back to native (so always works the same, and works with pretender) > > Why is this discussion happening now and not earlier? > > * ember 2 no longer supports IE8, and github/fetch is IE9+ > * fetch is a spec primitive of the DOM, it stands to reason we should prefer that over $.ajax > * maybe we can catch issues to help adapt/improve/add to the spec > * $.ajax is crazy quirky > * uploads have progress in the request object (unsure if the polifill does this or not actually, need to verify) > > Cons: > > * its not $.ajax which, although not a spec thing, is basically a primitive many devs are used to > * features like `$.ajaxPrefilter` are not obviously a thing in `fetch` (maybe some other approach ?) > * .... ? > > > Noop: > > * still no formal cancelation > > RFC: ember-cli/rfcs#19
I would like to propose that we consider using The addon already provides exception based error reporting and allows to customize what is considered a failed or successful response by overriding Using adapter pattern, we could make it possible for people to opt-in to using Thoughts? |
@taras what are the advantages of the transnational change vs backporting the changes? I'm struggling to see why not to make this transition; however real world demos would make this much easier too as mentioned. |
resolution: ic-ajax -> ember-fetch is to big of a jump for default, although we would encourage users to use fetch, the transition is non-obvious. Instead ic-ajax -> ember-ajax is the jump we are going to take. |
Why: * The ember-fetch RFC was an experiement that [failed]. * This is now the recommended approach from the ember-cli team. [failed]: ember-cli/rfcs#19 (comment) This change addresses the need by: * Updating the copy and sample to prefer ember-ajax over ic-ajax
Why: * The ember-fetch RFC was an experiement that [failed]. * This is now the recommended approach from the ember-cli team. [failed]: ember-cli/rfcs#19 (comment) This change addresses the need by: * Updating the copy and sample to prefer ember-ajax over ic-ajax
Lets begin this discussion.
What is ember-fetch?
Why is this discussion happening now and not earlier?
Cons:
$.ajaxPrefilter
are not obviously a thing infetch
(maybe some other approach ?)Noop:
things to check:
The text was updated successfully, but these errors were encountered: