Opened 10 years ago
Closed 9 years ago
#13717 closed feature (plugin)
$.Deferred helper methods to resolve/reject
Reported by: | danheberden | Owned by: | |
---|---|---|---|
Priority: | low | Milestone: | None |
Component: | deferred | Version: | 2.0b2 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
TL;DR the only way to change a failure to a resolution and vice-versa is to return a new promise. This is different from the promises/A spec (for good reason, I feel) but still is cumbersome to work with. I propose either:
$.Deferred.resolve(value); // returns a new, done promise with value $.Deferred.reject(value); // returns a new, failed promise with value
OR
since $.when already does this for synchronous content, create $.unless that takes any number args and only succeeds if all of them fail.
For details, implementation examples, and a fun time check out http://jsfiddle.net/danheberden/jhXAp/
xoxo, Dan
Change History (5)
comment:1 Changed 10 years ago by
comment:3 Changed 10 years ago by
Also, my mistake for not noticing then would work with a deferred and not just a promise, so $.Deferred().resolve(value) would be ok, albeit still a bit verbose.
comment:4 Changed 10 years ago by
Component: | unfiled → deferred |
---|---|
Priority: | undecided → low |
Status: | new → open |
comment:5 Changed 9 years ago by
Resolution: | → plugin |
---|---|
Status: | open → closed |
I don't think we are looking to add features, let's focus on Promise and see how we can integrate it. This can be done as a plugin if desired.
On my own projects, I have something as follows:
Not sure if they should be in core but we could use some Deferred-related plugins for sure.
Not a fan of
$.Deferred.resolve
, I don't see the gain compared to$.Deferred().resolve
.