File: index.html

package info (click to toggle)
jqapi 1.7%2Bdfsg-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid, trixie
  • size: 3,288 kB
  • sloc: javascript: 632; makefile: 12
file content (100 lines) | stat: -rw-r--r-- 4,414 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<!DOCTYPE html>
<html lang='en'><head><meta http-equiv='content-type' content='text/html; charset=UTF-8' /></head><body>
<div class="entry-content">
        <div class="entry-title roundTop">
          
          <h1 class="jq-clearfix">deferred.pipe()</h1>
          <div class="entry-meta jq-clearfix">
                        Categories:
            <span class="category"><a href="http://api.jquery.com/category/deferred-object/" title="View all posts in Deferred Object">Deferred Object</a></span>
  

          </div>

</div>
<div id="deferred-pipe1" class="entry method">
<h2 class="jq-clearfix roundTop section-title">
<span class="name">deferred.pipe(  [doneFilter]  [, failFilter]  )</span> <span class="returns">Returns: <a class="return" href="http://api.jquery.com/Types/#Promise">Promise</a></span>
</h2>
<div class="jq-box roundBottom entry-details">
<p class="desc"><strong>Description: </strong> Utility method to filter and/or chain Deferreds.  </p>
<ul class="signatures">
<li class="signature" id="deferred-pipe-doneFilter-failFilter">
<h4 class="name">
<span class="versionAdded">version added: <a href="/category/version/1.6/">1.6</a></span>deferred.pipe(  [doneFilter] [, failFilter] )</h4>
<p class="arguement"><strong>doneFilter</strong>
        An optional function that is called when the Deferred is resolved.
      </p>
<p class="arguement"><strong>failFilter</strong>
        An optional function that is called when the Deferred is rejected.
      </p>
</li>
<li class="signature" id="deferred-pipe-doneFilter-failFilter-progressFilter">
<h4 class="name">
<span class="versionAdded">version added: <a href="/category/version/1.7/">1.7</a></span>deferred.pipe(  [doneFilter] [, failFilter] [, progressFilter] )</h4>
<p class="arguement"><strong>doneFilter</strong>
        An optional function that is called when the Deferred is resolved.
      </p>
<p class="arguement"><strong>failFilter</strong>
        An optional function that is called when the Deferred is rejected.
      </p>
<p class="arguement"><strong>progressFilter</strong>
        An optional function that is called when the Deferred is rejected.
      </p>
</li>
</ul>
<div class="longdesc"><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></div>
<h3>Examples:</h3>
<div class="entry-examples" id="entry-examples">
<div id="example-0">
<h4>Example: <span class="desc">Filter resolve value:</span>
</h4>
<pre class="prettyprint"><code class="example">
var defer = $.Deferred(),
    filtered = defer.pipe(function( value ) {
      return value * 2;
    });

defer.resolve( 5 );
filtered.done(function( value ) {
  alert( "Value is ( 2*5 = ) 10: " + value );
});
</code></pre>
</div>
<div id="example-1">
<h4>Example: <span class="desc">Filter reject value:</span>
</h4>
<pre class="prettyprint"><code class="example">
var defer = $.Deferred(),
    filtered = defer.pipe( null, function( value ) {
      return value * 3;
    });

defer.reject( 6 );
filtered.fail(function( value ) {
  alert( "Value is ( 3*6 = ) 18: " + value );
});
</code></pre>
</div>
<div id="example-2">
<h4>Example: <span class="desc">Chain tasks:</span>
</h4>
<pre class="prettyprint"><code class="example">
var request = $.ajax( url, { dataType: "json" } ),
    chained = request.pipe(function( data ) {
      return $.ajax( url2, { data: { user: data.userId } } );
    });

chained.done(function( data ) {
  // data retrieved from url2 as provided by the first request
});

</code></pre>
</div>
</div>
</div>
</div>

        </div>

</body></html>