From cb296f6832295da9a6458507b5c6d8e55bec17c2 Mon Sep 17 00:00:00 2001 From: Leo Horie Date: Fri, 31 Oct 2014 21:50:19 -0400 Subject: [PATCH] #317 resolve w/ empty array if empty array --- mithril.js | 13 +++++++------ tests/mithril-tests.js | 6 ++++++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/mithril.js b/mithril.js index 4f5ffa35..f08f8b52 100644 --- a/mithril.js +++ b/mithril.js @@ -817,7 +817,7 @@ Mithril = m = new function app(window, undefined) { args[i].then(synchronizer(i, true), synchronizer(i, false)) } } - else deferred.resolve() + else deferred.resolve([]) return deferred.promise } @@ -885,17 +885,18 @@ Mithril = m = new function app(window, undefined) { if (maybeXhr != null) xhr = maybeXhr } + if (options.data && (!isStr(options.data) && options.data.constructor != window.FormData)) throw "Request data should be either be a string or FormData. Check the `serialize` option in `m.request`" xhr.send(options.method == "GET" || !options.data ? "" : options.data) return xhr } } function bindData(xhrOptions, data, serialize) { - if (data && Object.keys(data).length > 0) { - if (xhrOptions.method == "GET" && xhrOptions.dataType != "jsonp") { - xhrOptions.url = xhrOptions.url + (xhrOptions.url.indexOf("?") < 0 ? "?" : "&") + buildQueryString(data) - } - else xhrOptions.data = serialize(data) + if (xhrOptions.method == "GET" && xhrOptions.dataType != "jsonp") { + var prefix = xhrOptions.url.indexOf("?") < 0 ? "?" : "&" + var querystring = buildQueryString(data) + xhrOptions.url = xhrOptions.url + (querystring ? prefix + querystring : "") } + else xhrOptions.data = serialize(data) return xhrOptions } function parameterizeUrl(url, data) { diff --git a/tests/mithril-tests.js b/tests/mithril-tests.js index 494d1e15..0c48f068 100644 --- a/tests/mithril-tests.js +++ b/tests/mithril-tests.js @@ -1642,6 +1642,7 @@ function testMithril(mock) { test(function() { var prop = m.request({method: "GET", url: "test"}) mock.XMLHttpRequest.$instances.pop().onreadystatechange() + console.log(prop()) return prop().method === "GET" && prop().url === "test" }) test(function() { @@ -1977,6 +1978,11 @@ function testMithril(mock) { m.sync([]).then(function() {value = 2}) return value == 2 }) + test(function() { + var success + m.sync([]).then(function(value) {success = value instanceof Array}) + return success + }) //m.startComputation/m.endComputation test(function() {