JQuery

Delayed object-deferred.pipe([doneFilter],[failFilter],[progressFilter])

Delayed object-deferred.pipe([doneFilter],[failFilter],[progressFilter]), someone asked me to explain?

Overview

Utility methods for filters and/or chain Deferreds.

The deferred.pipe() method returns a new promise that passes a function related to the deferred state and value. The status and value of the resolve/rejection of the original Filter and failFilter filtering functions. These filter functions can return a new value that is passed to the pipe's promised done() or fail() callback, or they can return another observation object (deferred, promised, etc.) that will pass its resolve/reject status and Value to ensure the callback of the pipeline. If you are using the filter function null, or not specified, the pipeline's promise will be resolved or the original reject value will be the same.

Note: Starting with jQuery 1.8, the deferred.pipe() method is obsolete. Deferred.then() should be used instead.

parameter

doneFilter, failFilter V1.6

doneFilter : An optional function that is called when deferral is resolved.

failFilter : An optional function that is called when deferred is denied.

doneFilter, failFilter, progressFilter V1.7

doneFilter : An optional function that is called when deferral is resolved.

failFilter : An optional function that is called when deferred is denied.

progressFilter : An optional function will be called when the deferred call is rejected

Example

description:

Filter resolution value:

jQuery code:
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);
    });

description:

Filter rejection:

jQuery code:
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);
    });;

description:

Chain task:

jQuery code:
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
    });

 

 

Post your comments / questions