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

Adding Promise.fromDeferred helper to wrap jQuery Deferreds #42

Closed
wants to merge 1 commit into from

Conversation

kevinrobinson
Copy link

RSVP is great - thoroughly clear and small enough that it can be used as a fundamental abstraction across all my JS. I'm mostly working browser-side and mostly using $.Deferred now, and was surprised that it didn't chain the way I expected. In surveying the landscape, I didn't find a good fit, mostly for the same reasons you mentioned in http://news.ycombinator.com/item?id=4662222. So thanks!

I'm not sure if this fits with your goals for the project, but I think the idea to add helper functions that can wrap other promise abstractions into RSVP.Promises would be helpful in adopting it in my projects. This pull request adds that helper function for wrapping $.Deferred and is similar to #4 which wraps functions using Node-style callback parameters.

This is a little extra cruft (and basically useless for the Node build), so maybe this works better as an extension that is part of the project but a separate output of the build.

Thanks!

@kevinrobinson
Copy link
Author

Example usage:

  var deferred = $.Deferred();
  var rsvpPromise = RSVP.Promise.fromDeferred(deferred);
  rsvpPromise.then(function(args) {
    //in here, args will be equal to [1,2,3]
  });
  deferred.resolve(1,2,3);

@russelldavis
Copy link

+1 for this (or something similar from #60). One issue with this particular implementation -- if an exception gets thrown in the success handler for the original jQuery Deferred, this won't reject the deferred, which Promises/A+ requires.

@wagenet
Copy link
Contributor

wagenet commented Mar 27, 2013

@kevinrobinson Sorry for the slow activity on this. @wycats, is this something you're interested in?

@stefanpenner
Copy link
Collaborator

I believe #63 will provide the functionality you need and it does so by implementing the-promise-resolution-procedure

Let me know if #63 works for you

@stefanpenner
Copy link
Collaborator

I believe #63 addresses this.

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