You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
If I want to chain two HttpPromises and return the same Interface I currently have to do the following:
vargetStripeCustomerTokenFromCreditCard=function(creditcard){vardeferred=$q.defer();varpromise=deferred.promise;// wrap success and error to return consistent HttpPromise Interface// copied from angular.js, removed last parameter config in fn callbackpromise.success=function(fn){promise.then(function(response){fn(response.data,response.status,response.headers);});returnpromise;};promise.error=function(fn){promise.then(null,function(response){fn(response.data,response.status,response.headers);});returnpromise;};createCreditCardToken(creditcard).then(function(token){returncreateCustomerToken(token.data.id);}).then(deferred.resolve,deferred.reject);returnpromise;};
It's a bit long, I need $q, add the success, error boilerplate and then resolve the promise chain.
It would be great if this code could be reduced.
Perhaps I didn't grasp all the concepts and I could drastically reduce the amount of code required to achieve this task.
I wanted to attach some example code to this Issue, so one can see a use case.
I think that the proposal from @petebacondarwin is reasonable here. The problem is that there might be many promises created by different handlers in the whole chain - some of the function in a chain might have nothing to do with $http so I don't think we should second-guess that this is "$http promise".
Hey.
If I chain two
HttpPromise
withthe return value is a
Promise
and not aHttpPromise
.If chained
HttpPromises
would still beHttpPromise
their usage would be more consistentAdvantages:
The text was updated successfully, but these errors were encountered: