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

Decoration of $q defer.promise #5998

Closed
egobrain opened this Issue Jan 27, 2014 · 3 comments

Comments

Projects
None yet
6 participants
@egobrain

egobrain commented Jan 27, 2014

I want to decorate $q defer promise. Here is some code:

 $provide.decorator('$q', function ($delegate) {
    var defer = $delegate.defer;
    $delegate.defer = function () {
      var deferred = defer();
      deferred.promise.success = function (fn) {
        deferred.promise.then(function (value) {
          fn(value);
        });
        return deferred.promise;
      };
      deferred.promise.error = function (fn) {
        deferred.promise.then(null, function (value) {
          fn(value);
        });
        return deferred.promise;
      };
      return deferred;
    };
    return $delegate;

All is ok in simple case:

var def = $q.defer()
def.promise.success(function(data) {...});

But when i use $q functions like then, all, when returned promise has no success and error methods, because of internally $q closures old defer function implementation and uses non-decorated code for constructing defer objects.

@wejendorp

This comment has been minimized.

Show comment
Hide comment
@wejendorp

wejendorp May 20, 2014

I made a post about this issue and a way around it on my blog:
Extending $q promises

Check it out if it's still relevant.

wejendorp commented May 20, 2014

I made a post about this issue and a way around it on my blog:
Extending $q promises

Check it out if it's still relevant.

@lawrencejones

This comment has been minimized.

Show comment
Hide comment
@lawrencejones

lawrencejones Jul 15, 2014

@wejendorp very nice, thanks for that!

lawrencejones commented Jul 15, 2014

@wejendorp very nice, thanks for that!

@btford btford removed the gh: issue label Aug 20, 2014

@lgalfaso

This comment has been minimized.

Show comment
Hide comment
@lgalfaso

lgalfaso Jan 3, 2015

Member

With the post from @wejendorp, I think this can be closed

Member

lgalfaso commented Jan 3, 2015

With the post from @wejendorp, I think this can be closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment