wookiehangover / underscore.deferred

jQuery style Deferreds for Underscore
https://github.com/wookiehangover/underscore.deferred
MIT License
225 stars 21 forks source link

mixed promise state when filtering using then() #17

Closed thomheymann closed 11 years ago

thomheymann commented 11 years ago

The library is mixing up promise states when filtering return values:

var defer = $.Deferred(),
    filtered = defer.then( null, function( value ) {
        return value * 3;
    });

defer.reject( 6 );
filtered.fail(function( value ) {
    console.log( "Value is ( 3*6 = ) 18: " + value );
});
filtered.always(function( value ) {
    console.log( "State is: " + defer.state() );
    console.log( "Filtered State is: " + filtered.state() );
});

In browser using jQuery 1.8:

Value is ( 3*6 = ) 18: 18
State is: rejected
Filtered State is: rejected

In node using underscore.deferred:

State is: rejected
Filtered State is: resolved

I'm on 0.4.0 installed via npm

wookiehangover commented 11 years ago

This is expected behavior.

As specified, .then issues another promise, rather than holding the reference to the original promise that it's chaining from. This is a breaking change from the jQuery implementation, and is documented in the readme for 0.4.0. Take a look at @domenic's explanation of this part of the promises A spec for the detailed reasoning behind this change.

Apologies for the confusion!