Bug Tracker

Opened 9 years ago

Last modified 8 years ago

#9398 closed enhancement

Proposal for Improved Deferreds — at Version 9

Reported by: jaubourg Owned by: jaubourg
Priority: blocker Milestone: 1.7
Component: deferred Version: 1.6.1
Keywords: 1.7-discuss Cc:
Blocked by: Blocking:

Description (last modified by john)

This proposal is a two parter:

  1. introduce progress callbacks on Deferreds (just as suggested in the Promise/A proposal). It's kind of a first step before being able to support xhr2 upload and is a much needed addition when dealing with asynchronous tasks that take a non-trivial amount of time to complete and would profit from progression notifications,
  2. while working on adding progress callbacks I realized that, while different, the logic for the progress callbacks list wasn't that far away from the one of the other two callbacks lists (the only real difference being that the progress callbacks can be called several times, while done and fail ones are only fired once). This brought me to scrap $._Deferred and go for a much more generic $.Callbacks. The advantage is that I can now implement done, fail and progress callbacks with the same base object. It also gives us an opportunity to factor our different callbacks lists throughout jQuery (meaning more robustness and a diminished code size). It can also be made public so that users can start creating callbacks lists easily.

All my experiments are located in the 1.7/callbacks branch. Still a work in progress, of course. Progress callbacks are in (though buggy atm because I screwed the memory logic of repeatable Callbacks but I'm working on it), $.when supports progress callbacks already. All instances of $._Deferred have been replaced by $.Callbacks objects.

To have an idea of how it would work, see:

Change History (9)

comment:1 Changed 9 years ago by john

Keywords: 1.7-discuss added

Nominating ticket for 1.7 discussion.

comment:2 Changed 9 years ago by Rick Waldron

Description: modified (diff)

+1, DRY opportunity

comment:3 Changed 9 years ago by jaubourg

+1,

comment:4 Changed 9 years ago by timmywil

+1,

comment:5 Changed 9 years ago by jaubourg

Description: modified (diff)

I added a crude named channel system to give an idea of how pub/sub could be implemented using $.Callbacks: https://github.com/jquery/jquery/commit/96b0089c9ce5c65f9d002966256d90e778345a2a

comment:6 Changed 9 years ago by jaubourg

Description: modified (diff)

comment:7 Changed 9 years ago by timmywil

Component: unfileddeferred
Owner: set to jaubourg
Priority: undecidedhigh
Status: newassigned

comment:8 Changed 9 years ago by dmethvin

+1, Let me get this straight. Jaubourg is proposing to reduce code size? Damn I'm gonna vote for this just to see him try!

comment:9 Changed 9 years ago by john

Description: modified (diff)

+0

Note: See TracTickets for help on using tickets.