Merge pull request #739 from dgilland/origin/feature-propify-finally

Don't pass value/reason to promise.finally callback.
This commit is contained in:
Leo Horie 2015-08-04 15:03:47 -04:00
commit 7a5980631e
2 changed files with 6 additions and 6 deletions

View file

@ -1086,12 +1086,12 @@ var m = (function app(window, undefined) {
return propify(promise.then(resolve, reject), initialValue); return propify(promise.then(resolve, reject), initialValue);
}; };
prop["catch"] = prop.then.bind(null, null); prop["catch"] = prop.then.bind(null, null);
prop["finally"] = function(callback){ prop["finally"] = function(callback) {
var _callback = function(value){return m.deferred().resolve(callback(value)).promise;}; var _callback = function() {return m.deferred().resolve(callback()).promise;};
return prop.then(function(value) { return prop.then(function(value) {
return propify(_callback(value).then(function() {return value;}), initialValue); return propify(_callback().then(function() {return value;}), initialValue);
}, function(reason) { }, function(reason) {
return propify(_callback(reason).then(function() {throw new Error(reason);}), initialValue); return propify(_callback().then(function() {throw new Error(reason);}), initialValue);
}); });
}; };
return prop; return prop;

View file

@ -3923,11 +3923,11 @@ function testMithril(mock) {
return prop().message === "error occurred" && error().message === "error occurred" return prop().message === "error occurred" && error().message === "error occurred"
}) })
test(function() { test(function() {
// Data returned by then() functions propagate to finally(). // Data returned by then() functions do *not* propagate to finally().
var data = m.prop(""); var data = m.prop("");
var prop = m.request({method: "GET", url: "test"}).then(function() {return "foo"})["finally"](data) var prop = m.request({method: "GET", url: "test"}).then(function() {return "foo"})["finally"](data)
mock.XMLHttpRequest.$instances.pop().onreadystatechange() mock.XMLHttpRequest.$instances.pop().onreadystatechange()
return prop() === "foo" && data() === "foo" return prop() === "foo" && data() === ""
}) })
test(function() { test(function() {
// Data returned by finally() functions do *not* propagate to next promise. // Data returned by finally() functions do *not* propagate to next promise.