diff --git a/docs/change-log.md b/docs/change-log.md index 8fb182f8..273cd0b1 100644 --- a/docs/change-log.md +++ b/docs/change-log.md @@ -13,6 +13,7 @@ - fix routing bug in IE9 [#320](https://github.com/lhorie/mithril.js/issues/320) - fix ordering bug in m.trust when using HTML entities [#453](https://github.com/lhorie/mithril.js/issues/453) +- set promise's default value to initialValue if coming from m.request [#454](https://github.com/lhorie/mithril.js/issues/454) --- diff --git a/docs/mithril.request.md b/docs/mithril.request.md index ad89a482..2b474861 100644 --- a/docs/mithril.request.md +++ b/docs/mithril.request.md @@ -433,8 +433,8 @@ where: [Object data,] [Boolean background,] [any initialValue,] - [any unwrapSuccess(any data),] - [any unwrapError(any data),] + [any unwrapSuccess(any data, XMLHttpRequest xhr),] + [any unwrapError(any data, XMLHttpRequest xhr),] [String serialize(any dataToSerialize),] [any deserialize(String dataToDeserialize),] [any extract(XMLHttpRequest xhr, XHROptions options),] diff --git a/docs/tools.md b/docs/tools.md index 99833267..a0c0ae76 100644 --- a/docs/tools.md +++ b/docs/tools.md @@ -57,7 +57,7 @@ You can use it by adding a reference to your Typescript files. This will allow t ### Internet Explorer Compatibility -Mithril relies on some Ecmascript 5 features, namely: `Array::indexOf`, `Array::map` and `Object::keys`, as well as the `JSON` object. +Mithril relies on some ECMAScript 5 features, namely: `Array::indexOf`, `Array::map` and `Object::keys`, as well as the `JSON` object. Internet Explorer 8 lacks native support for some of these features. The easiest way to polyfill these features is to include this script: @@ -79,4 +79,4 @@ You can also use other polyfills to support these features in IE7. Mithril also has a dependency on XMLHttpRequest. If you wish to support IE6, you'll need [a shim for it](https://gist.github.com/Contra/2709462). IE7 and lower do not support cross-domain AJAX requests. -In addition, note that most `m.route` modes rely on `history.pushState` in order to allow moving from one page to another without a browser refresh. [IE9 and lower](http://caniuse.com/#search=pushstate) do not support this feature and will gracefully degrade to page refreshes instead. \ No newline at end of file +In addition, note that most `m.route` modes rely on `history.pushState` in order to allow moving from one page to another without a browser refresh. [IE9 and lower](http://caniuse.com/#search=pushstate) do not support this feature and will gracefully degrade to page refreshes instead. diff --git a/mithril.js b/mithril.js index b8b81407..fd9e7b08 100644 --- a/mithril.js +++ b/mithril.js @@ -786,7 +786,8 @@ var m = (function app(window, undefined) { var prop = m.prop(); promise.then(prop); prop.then = function(resolve, reject) { - return propify(promise.then(resolve, reject)) + promise = promise.then(resolve, reject).then(prop); + return prop; }; return prop } diff --git a/tests/mithril-tests.js b/tests/mithril-tests.js index 2e620c78..2bc85452 100644 --- a/tests/mithril-tests.js +++ b/tests/mithril-tests.js @@ -2227,6 +2227,13 @@ function testMithril(mock) { xhr.onreadystatechange() return xhr.$headers["Content-Type"] === undefined }) + test(function() { + var prop = m.request({method: "POST", url: "test", initialValue: "foo"}).then(function(data) { return data; }) + var initialValue = prop(); + mock.XMLHttpRequest.$instances.pop().onreadystatechange() + + return initialValue === "foo" + }) test(function() { var prop = m.request({method: "POST", url: "test", initialValue: "foo"}) var initialValue = prop();