From 71a6321c467ae33cfaeff104982418b53ca6adf3 Mon Sep 17 00:00:00 2001 From: Barney Date: Sun, 9 Nov 2014 13:34:04 +0000 Subject: [PATCH] m.request default parameter allows immediate invocation of returned m.prop --- mithril.js | 1 + tests/mithril-tests.js | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/mithril.js b/mithril.js index 91348bb4..c28ec3ad 100644 --- a/mithril.js +++ b/mithril.js @@ -949,6 +949,7 @@ Mithril = m = new function app(window, undefined) { if (xhrOptions.background !== true) m.endComputation() } ajax(xhrOptions) + deferred.promise(xhrOptions.default) return deferred.promise } diff --git a/tests/mithril-tests.js b/tests/mithril-tests.js index 56c73b52..560a34ef 100644 --- a/tests/mithril-tests.js +++ b/tests/mithril-tests.js @@ -1687,6 +1687,15 @@ function testMithril(mock) { xhr.onreadystatechange() return xhr.$headers["Content-Type"] === undefined }) + test(function() { + var prop = m.request({method: "POST", url: "test", default: "foo"}) + return prop() === "foo" + }) + test(function() { + var prop = m.request({method: "POST", url: "test", default: "foo"}).then(function(value) {return "bar"}) + mock.XMLHttpRequest.$instances.pop().onreadystatechange() + return prop() === "bar" + }) // m.request over jsonp test(function(){