diff --git a/request/request.js b/request/request.js index 07f4a454..3feedf15 100644 --- a/request/request.js +++ b/request/request.js @@ -11,6 +11,7 @@ module.exports = function($window) { function xhr(args) { var stream = Stream.stream() + if (args.initialValue !== undefined) stream(args.initialValue) var useBody = typeof args.useBody === "boolean" ? args.useBody : args.method !== "GET" && args.method !== "TRACE" diff --git a/request/tests/test-xhr.js b/request/tests/test-xhr.js index 14f3ba0f..830a5625 100644 --- a/request/tests/test-xhr.js +++ b/request/tests/test-xhr.js @@ -241,6 +241,16 @@ o.spec("xhr", function() { o(typeof xhr.send).equals("function") } }) + o("initialValue parameter works", function() { + mock.$defineRoutes({ + "GET /items": function() { + return {status: 200, responseText: JSON.stringify([{a: 1}])} + } + }) + var items = xhr({method: "GET", url: "/items", initialValue: []}) + + o(items()).deepEquals([]) + }) }) o.spec("failure", function() { o("rejects on server error", function(done) {