Skip to content

Commit 6b565fa

Browse files
committed
Add jQuery.Deferred() entry (replacing some deferred object desc)
1 parent 20172f6 commit 6b565fa

File tree

3 files changed

+39
-20
lines changed

3 files changed

+39
-20
lines changed

categories.xml

+3-16
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,8 @@
3131
<desc><![CDATA[These methods allow us to associate arbitrary data with specific DOM elements.]]></desc>
3232
</category>
3333
<category name="Deferred Object" slug="deferred-object">
34-
<desc><![CDATA[
35-
<p><code>jQuery.Deferred()</code>, introduced in version 1.5, is a chainable utility object that can register multiple callbacks into callback queues, invoke callback queues, and relay the success or failure state of any synchronous or asynchronous function.</p>
36-
<div class="longdesc">
37-
<p>In JavaScript it is common to invoke functions that optionally accept callbacks that are called within that function.</p>
38-
<p>For example, in versions prior to jQuery 1.5, asynchronous processes such as <code>jQuery.ajax()</code> accept callbacks to be invoked some time in the near-future upon success, error, and completion of the ajax request.</p>
39-
<p><code>jQuery.Deferred()</code> introduces several enhancements to the way callbacks are managed and invoked. In particular, <code>jQuery.Deferred()</code> provides flexible ways to provide multiple callbacks, and these callbacks can be invoked regardless of whether the original callback dispatch has already occurred. jQuery Deferred is based on the <a href="http://wiki.commonjs.org/wiki/Promises/A">CommonJS Promises/A</a> design.</p>
40-
<p>One model for understanding Deferred is to think of it as a chain-aware function wrapper. The <a href="http://api.jquery.com/deferred.then"><code>deferred.then()</code></a>, <a href="http://api.jquery.com/deferred.done"><code>deferred.done()</code></a>, and <a href="http://api.jquery.com/deferred.fail"><code>deferred.fail()</code></a> methods specify the functions to be called and the <a href="http://api.jquery.com/deferred.resolve"><code>deferred.resolve(args)</code></a> or <a href="http://api.jquery.com/deferred.reject"><code>deferred.reject(args)</code></a> methods "call" the functions with the arguments you supply. Once the Deferred has been resolved or rejected it stays in that state; a second call to <code>deferred.resolve()</code> is ignored for example. If more functions are added by <code>deferred.then()</code> after the Deferred is resolved, they are called immediately with the arguments previously provided.</p>
41-
<p>In most cases where a jQuery API call returns a Deferred or Deferred-compatible object, such as <a href="http://api.jquery.com/jQuery.ajax"><code>jQuery.ajax()</code></a> or <a href="http://api.jquery.com/jQuery.when"><code>jQuery.when()</code></a>, you will only want to use the <a href="http://api.jquery.com/deferred.then"><code>deferred.then()</code></a>, <a href="http://api.jquery.com/deferred.done"><code>deferred.done()</code></a>, and <a href="http://api.jquery.com/deferred.fail"><code>deferred.fail()</code></a> methods to add callbacks to the Deferred's queues. The internals of the API call or code that created the Deferred will invoke <a href="http://api.jquery.com/deferred.resolve"><code>deferred.resolve()</code></a> or <a href="http://api.jquery.com/deferred.reject"><code>deferred.reject()</code></a> on the deferred at some point, causing the appropriate callbacks to run.</p>
42-
<h4>jQuery.Deferred Constructor</h4>
43-
<p>The <code>jQuery.Deferred()</code> constructor creates a new Deferred object. The <code>new</code> operator is optional.</p>
44-
<p><code>jQuery.Deferred</code> can be passed an optional function, which is called just before the constructor returns and is passed the constructed <code>deferred</code> object as both the <code>this</code> object and as the first argument to the function. The called function can attach callbacks using <a href="http://api.jquery.com/deferred.then"><code>deferred.then()</code></a> for example.</p>
45-
<p>A Deferred object starts in the <em>pending</em> state. Any callbacks added to the object with <a href="http://api.jquery.com/deferred.then"><code>deferred.then()</code></a>, <a href="http://api.jquery.com/deferred.done"><code>deferred.done()</code></a>, or <a href="http://api.jquery.com/deferred.fail"><code>deferred.fail()</code></a> are queued to be executed later. Calling <a href="http://api.jquery.com/deferred.resolve"><code>deferred.resolve()</code></a> or <a href="http://api.jquery.com/deferred.resolveWith"><code>deferred.resolveWith()</code></a> transitions the Deferred into the <em>resolved</em> state and immediately executes any <code>doneCallbacks</code> that are set. Calling <a href="http://api.jquery.com/deferred.reject"><code>deferred.reject()</code></a> or <a href="http://api.jquery.com/deferred.rejectWith"><code>deferred.rejectWith()</code></a> transitions the Deferred into the <em>rejected</em> state and immediately executes any <code>failCallbacks</code> that are set. Once the object has entered the resolved or rejected state, it stays in that state. Callbacks can still be added to the resolved or rejected Deferred -- they will execute immediately.</p>
46-
<p>The Deferred object is chainable, similar to the way a jQuery object is chainable, but it has its own methods. After creating a Deferred object, you can use any of the methods below by either chaining directly from the object creation or saving the object in a variable and invoking one or more methods on that variable.</p>
47-
</div>
48-
]]></desc>
34+
<desc><![CDATA[<p>The Deferred object, introduced in jQuery 1.5, is a chainable utility object created by calling the <a href="/jQuery.Deferred/"><code>jQuery.Deferred()</code></a> method. It can register multiple callbacks into callback queues, invoke callback queues, and relay the success or failure state of any synchronous or asynchronous function.</p>
35+
<p>The Deferred object is chainable, similar to the way a jQuery object is chainable, but it has its own methods. After creating a Deferred object, you can use any of the methods below by either chaining directly from the object creation or saving the object in a variable and invoking one or more methods on that variable.</p>]]></desc>
4936
</category>
5037
<category name="Deprecated" slug="deprecated">
5138
<desc><![CDATA[These items have been deprecated, though not necessarily removed, from jQuery.]]></desc>
@@ -383,4 +370,4 @@
383370
</category>
384371
<category name="All" slug="all"/>
385372
</category>
386-
</categories>
373+
</categories>

entries/jQuery.Deferred.xml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0"?>
2+
<entry name="jQuery.Deferred" type="method" return="Deferred">
3+
<title>jQuery.Deferred()</title>
4+
<signature>
5+
<added>1.5</added>
6+
<argument name="beforeStart" type="Function" optional="true">
7+
<desc>
8+
A function that is called just before the constructor returns.
9+
</desc>
10+
<argument name="deferred" type="Deferred">
11+
<desc>
12+
The constructed Deferred object.
13+
</desc>
14+
</argument>
15+
</argument>
16+
</signature>
17+
<desc> A constructor function that returns a chainable utility object with methods to register multiple callbacks into callback queues, invoke callback queues, and relay the success or failure state of any synchronous or asynchronous function.</desc>
18+
<longdesc>
19+
<p>The <code>jQuery.Deferred()</code> constructor creates a new Deferred object. The <code>new</code> operator is optional.</p>
20+
<p>The <code>jQuery.Deferred</code> method can be passed an optional function, which is called just before the constructor returns and is passed the constructed <code>deferred</code> object as both the <code>this</code> object and as the first argument to the function. The called function can attach callbacks using <a href="/deferred.then"><code>deferred.then()</code></a>, for example.</p>
21+
<p>A Deferred object starts in the <em>pending</em> state. Any callbacks added to the object with <a href="/deferred.then"><code>deferred.then()</code></a>, <a href="/deferred.always"><code>deferred.always()</code></a>, <a href="/deferred.done"><code>deferred.done()</code></a>, or <a href="/deferred.fail"><code>deferred.fail()</code></a> are queued to be executed later. Calling <a href="/deferred.resolve"><code>deferred.resolve()</code></a> or <a href="/deferred.resolveWith"><code>deferred.resolveWith()</code></a> transitions the Deferred into the <em>resolved</em> state and immediately executes any <code>doneCallbacks</code> that are set. Calling <a href="/deferred.reject"><code>deferred.reject()</code></a> or <a href="/deferred.rejectWith"><code>deferred.rejectWith()</code></a> transitions the Deferred into the <em>rejected</em> state and immediately executes any <code>failCallbacks</code> that are set. Once the object has entered the resolved or rejected state, it stays in that state. Callbacks can still be added to the resolved or rejected Deferred — they will execute immediately.</p>
22+
<h4>
23+
Enhanced Callbacks with jQuery Deferred
24+
</h4>
25+
<p>In JavaScript it is common to invoke functions that optionally accept callbacks that are called within that function. For example, in versions prior to jQuery 1.5, asynchronous processes such as <code>jQuery.ajax()</code> accept callbacks to be invoked some time in the near-future upon success, error, and completion of the ajax request.</p>
26+
<p><code>jQuery.Deferred()</code> introduces several enhancements to the way callbacks are managed and invoked. In particular, <code>jQuery.Deferred()</code> provides flexible ways to provide multiple callbacks, and these callbacks can be invoked regardless of whether the original callback dispatch has already occurred. jQuery Deferred is based on the <a href="http://wiki.commonjs.org/wiki/Promises/A">CommonJS Promises/A</a> design.</p>
27+
<p>One model for understanding Deferred is to think of it as a chain-aware function wrapper. The <a href="/deferred.then"><code>deferred.then()</code></a>, <a href="/deferred.always"><code>deferred.always()</code></a>, <a href="/deferred.done"><code>deferred.done()</code></a>, and <a href="/deferred.fail"><code>deferred.fail()</code></a> methods specify the functions to be called and the <a href="/deferred.resolve"><code>deferred.resolve(args)</code></a> or <a href="/deferred.reject"><code>deferred.reject(args)</code></a> methods "call" the functions with the arguments you supply. Once the Deferred has been resolved or rejected it stays in that state; a second call to <code>deferred.resolve()</code>, for example, is ignored. If more functions are added by <code>deferred.then()</code>, for example, after the Deferred is resolved, they are called immediately with the arguments previously provided.</p>
28+
<p>In most cases where a jQuery API call returns a Deferred or Deferred-compatible object, such as <a href="/jQuery.ajax"><code>jQuery.ajax()</code></a> or <a href="/jQuery.when"><code>jQuery.when()</code></a>, you will only want to use the <a href="/deferred.then"><code>deferred.then()</code></a>, <a href="/deferred.done"><code>deferred.done()</code></a>, and <a href="/deferred.fail"><code>deferred.fail()</code></a> methods to add callbacks to the Deferred's queues. The internals of the API call or code that created the Deferred will invoke <a href="/deferred.resolve"><code>deferred.resolve()</code></a> or <a href="/deferred.reject"><code>deferred.reject()</code></a> on the deferred at some point, causing the appropriate callbacks to run.</p>
29+
</longdesc>
30+
<category slug="deferred-object"/>
31+
<category slug="version/1.5"/>
32+
</entry>

pages/Types.html

+4-4
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@
8484
<li class="toclevel-1"><a href="#jQuery"><span class="toctext">jQuery</span></a></li>
8585
<li class="toclevel-1"><a href="#XMLHttpRequest"><span class="toctext">XMLHttpRequest</span></a></li>
8686
<li class="toclevel-1"><a href="#jqXHR"><span class="toctext">jqXHR</span></a></li>
87-
<li class="toclevel-1"><a href="#Deferred"><span class="toctext">Deferred</span></a></li>
88-
<li class="toclevel-1"><a href="#Promise"><span class="toctext">Promise</span></a></li>
87+
<li class="toclevel-1"><a href="#Deferred"><span class="toctext">Deferred Object</span></a></li>
88+
<li class="toclevel-1"><a href="#Promise"><span class="toctext">Promise Object</span></a></li>
8989
<li class="toclevel-1"><a href="#Callbacks"><span class="toctext">Callbacks Object</span></a></li>
9090
</ol>
9191

@@ -582,10 +582,10 @@ <h2 id="XMLHttpRequest"> XMLHttpRequest </h2>
582582
<h2 id="jqXHR"> jqXHR </h2>
583583
<p>As of jQuery 1.5, the <a href="http://api.jquery.com/jQuery.ajax/">$.ajax()</a> method returns the jqXHR object, which is a superset of the XMLHTTPRequest object. For more information, see the <a href="http://api.jquery.com/jQuery.ajax/#jqXHR">jqXHR section of the $.ajax entry</a>
584584
</p>
585-
<h2 id="Deferred"> Deferred </h2>
585+
<h2 id="Deferred"> Deferred Object</h2>
586586
<p>As of jQuery 1.5, the <a href="http://api.jquery.com/category/deferred-object">Deferred</a> object provides a way to register multiple callbacks into self-managed callback queues, invoke callback queues as appropriate, and relay the success or failure state of any synchronous or asynchronous function.</a>
587587
</p>
588-
<h2 id="Promise"> Promise </h2>
588+
<h2 id="Promise"> Promise Object</h2>
589589
<p>This object provides a subset of the methods of the <a href="http://api.jquery.com/category/deferred-object">Deferred</a> object (<a href="http://api.jquery.com/deferred.then/"><code>then</code></a>, <a href="http://api.jquery.com/deferred.done/"><code>done</code></a>, <a href="http://api.jquery.com/deferred.fail/"><code>fail</code></a>, <a href="http://api.jquery.com/deferred.always"><code>always</code></a>, <a href="http://api.jquery.com/deferred.pipe/"><code>pipe</code></a>. <a href="http://api.jquery.com/deferred.isResolved/"><code>isResolved</code></a>, and <a href="http://api.jquery.com/deferred.isRejected/"><code>isRejected</code></a>) to prevent users from changing the state of the Deferred.</a>
590590
</p>
591591
<h2 id="Callbacks">Callbacks Object</h2>

0 commit comments

Comments
 (0)