1 line
3.1 KiB
JSON
1 line
3.1 KiB
JSON
{"name":"deferred.pipe","type":"method","title":"deferred.pipe()","deprecated":"1.8","removed":null,"desc":" Utility method to filter and/or chain Deferreds. ","categories":["deferred-object","version/1.6","version/1.7","version/1.8","deprecated/deprecated-1.8"],"entries":[{"return":"Promise","signatures":[{"added":"1.6","argument":[{"desc":"\n An optional function that is called when the Deferred is resolved.\n ","name":"doneFilter","type":"Function","optional":"true"},{"desc":"\n An optional function that is called when the Deferred is rejected.\n ","name":"failFilter","type":"Function","optional":"true"}]},{"added":"1.7","argument":[{"desc":"\n An optional function that is called when the Deferred is resolved.\n ","name":"doneFilter","type":"Function","optional":"true"},{"desc":"\n An optional function that is called when the Deferred is rejected.\n ","name":"failFilter","type":"Function","optional":"true"},{"desc":"\n An optional function that is called when progress notifications are sent to the Deferred.\n ","name":"progressFilter","type":"Function","optional":"true"}]}],"examples":[{"desc":"Filter resolve value:","code":"\nvar defer = $.Deferred(),\n filtered = defer.pipe(function( value ) {\n return value * 2;\n });\n\ndefer.resolve( 5 );\nfiltered.done(function( value ) {\n alert( \"Value is ( 2*5 = ) 10: \" + value );\n});\n"},{"desc":"Filter reject value:","code":"\nvar defer = $.Deferred(),\n filtered = defer.pipe( null, function( value ) {\n return value * 3;\n });\n\ndefer.reject( 6 );\nfiltered.fail(function( value ) {\n alert( \"Value is ( 3*6 = ) 18: \" + value );\n});\n"},{"desc":"Chain tasks:","code":"\nvar request = $.ajax( url, { dataType: \"json\" } ),\n chained = request.pipe(function( data ) {\n return $.ajax( url2, { data: { user: data.userId } } );\n });\n\nchained.done(function( data ) {\n // data retrieved from url2 as provided by the first request\n});\n"}],"longdesc":"\n <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>\n <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>\n "}]} |