#317 resolve w/ empty array if empty array

This commit is contained in:
Leo Horie 2014-10-31 21:50:19 -04:00
parent 19f5878592
commit cb296f6832
2 changed files with 13 additions and 6 deletions

View file

@ -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) {

View file

@ -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() {