Merge pull request #333 from barneycarroll/propSafeRequest

`initialValue` property for `m.request`, with tests
This commit is contained in:
Leo Horie 2014-11-12 09:55:03 -05:00
commit 092683382a
2 changed files with 13 additions and 0 deletions

View file

@ -949,6 +949,7 @@ Mithril = m = new function app(window, undefined) {
if (xhrOptions.background !== true) m.endComputation()
}
ajax(xhrOptions)
deferred.promise(xhrOptions.initialValue)
return deferred.promise
}

View file

@ -1687,6 +1687,18 @@ function testMithril(mock) {
xhr.onreadystatechange()
return xhr.$headers["Content-Type"] === undefined
})
test(function() {
var prop = m.request({method: "POST", url: "test", initialValue: "foo"})
var initialValue = prop();
mock.XMLHttpRequest.$instances.pop().onreadystatechange()
return initialValue === "foo"
})
test(function() {
var prop = m.request({method: "POST", url: "test", initialValue: "foo"}).then(function(value) {return "bar"})
mock.XMLHttpRequest.$instances.pop().onreadystatechange()
return prop() === "bar"
})
// m.request over jsonp
test(function(){