You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<desc> Utility method to filter and/or chain Deferreds. </desc>
36
36
<longdesc>
37
+
<p><strong>Deprecation Notice:</strong>As of jQuery 1.8, the deferred.pipe() method is deprecated. The <code>deferred.then()</code> method, which replaces it, should be used instead.</p>
37
38
<p>The <code>deferred.pipe()</code> method returns a new promise that filters the status and values of a deferred through a function. The <code>doneFilter</code> and <code>failFilter</code> functions filter the original deferred's resolved / rejected status and values. <strong>As of jQuery 1.7</strong>, the method also accepts a <code>progressFilter</code> function to filter any calls to the original deferred's <code>notify</code> or <code>notifyWith</code> methods. These filter functions can return a new value to be passed along to the piped promise's <code>done()</code> or <code>fail()</code> callbacks, or they can return another observable object (Deferred, Promise, etc) which will pass its resolved / rejected status and values to the piped promise's callbacks. If the filter function used is <code>null</code>, or not specified, the piped promise will be resolved or rejected with the same values as the original.</p>
An optional function that is called when progress notifications are sent to the Deferred.
19
+
</desc>
20
+
</argument>
21
+
</signature>
4
22
<signature>
5
23
<added>1.5</added>
24
+
<removed>1.8</removed>
6
25
<argumentname="doneCallbacks"type="Function">
7
26
<desc>
8
27
A function, or array of functions, called when the Deferred is resolved.
@@ -16,6 +35,7 @@
16
35
</signature>
17
36
<signature>
18
37
<added>1.7</added>
38
+
<removed>1.8</removed>
19
39
<argumentname="doneCallbacks"type="Function">
20
40
<desc>
21
41
A function, or array of functions, called when the Deferred is resolved.
@@ -32,10 +52,14 @@
32
52
</desc>
33
53
</argument>
34
54
</signature>
35
-
<desc> Add handlers to be called when the Deferred object is resolved or rejected. </desc>
55
+
<desc>Add handlers to be called when the Deferred object is resolved, rejected, or still in progress. </desc>
56
+
36
57
<longdesc>
37
-
<p>All three arguments (including progressCallbacks, as of jQuery 1.7) can be either a single function or an array of functions. The arguments can also be <code>null</code> if no callback of that type is desired. Alternatively, use <code>.done()</code>, <code>.fail()</code> or <code>.progress()</code> to set only one type of callback. </p>
38
-
<p>When the Deferred is resolved, the doneCallbacks are called. If the Deferred is instead rejected, the failCallbacks are called. As of jQuery 1.7, the <code>deferred.notify()</code> or <code>deferred.notifyWith()</code> methods can be called to invoke the progressCallbacks as many times as desired before the Deferred is resolved or rejected.</p>
58
+
<p><strong>Prior to jQuery 1.8</strong>, the arguments could be a function or an array of functions.</p>
59
+
<p>For all signatures, the arguments can be <code>null</code> if no callback of that type is desired. Alternatively, use <code>.done()</code>, <code>.fail()</code> or <code>.progress()</code> to set only one type of callback without filtering status or values. </p>
60
+
61
+
<p><strong>As of jQuery 1.8</strong>, the <code>deferred.then()</code> method returns a new promise that can filter the status and values of a deferred through a function, replacing the now-deprecated <code>deferred.pipe()</code> method. The <code>doneFilter</code> and <code>failFilter</code> functions filter the original deferred's resolved / rejected status and values. The <code>progressFilter</code> function filters any calls to the original deferred's <code>notify</code> or <code>notifyWith</code> methods. These filter functions can return a new value to be passed along to the promise's <code>.done()</code> or <code>.fail()</code> callbacks, or they can return another observable object (Deferred, Promise, etc) which will pass its resolved / rejected status and values to the promise's callbacks. If the filter function used is <code>null</code>, or not specified, the promise will be resolved or rejected with the same values as the original.</p>
62
+
39
63
<p>Callbacks are executed in the order they were added. Since
40
64
<code>deferred.then</code> returns a Promise, other methods of the
41
65
Promise object can be chained to this one, including additional
@@ -49,6 +73,58 @@ $.get("test.php").then(
49
73
function(){ alert("$.get succeeded"); },
50
74
function(){ alert("$.get failed!"); }
51
75
);
76
+
]]></code>
77
+
</example>
78
+
<example>
79
+
<desc>Filter the resolve value:</desc>
80
+
<html><![CDATA[
81
+
<button>Filter Resolve</button>
82
+
<p></p>
83
+
]]></html>
84
+
<code><![CDATA[
85
+
var filterResolve = function() {
86
+
87
+
var defer = $.Deferred(),
88
+
filtered = defer.then(function( value ) {
89
+
return value * 2;
90
+
});
91
+
92
+
defer.resolve( 5 );
93
+
filtered.done(function( value ) {
94
+
$( "p" ).html( "Value is ( 2*5 = ) 10: " + value );
95
+
});
96
+
};
97
+
98
+
$( "button" ).on( "click", filterResolve );
99
+
]]></code>
100
+
101
+
</example>
102
+
<example>
103
+
<desc>Filter reject value:</desc>
104
+
<code><![CDATA[
105
+
var defer = $.Deferred(),
106
+
filtered = defer.then( null, function( value ) {
107
+
return value * 3;
108
+
});
109
+
110
+
defer.reject( 6 );
111
+
filtered.fail(function( value ) {
112
+
alert( "Value is ( 3*6 = ) 18: " + value );
113
+
});
114
+
]]></code>
115
+
</example>
116
+
<example>
117
+
<desc>Chain tasks:</desc>
118
+
<code><![CDATA[
119
+
var request = $.ajax( url, { dataType: "json" } ),
0 commit comments