feat: Add support for timeout to m.request (#1966)
This commit is contained in:
parent
a382c85eb0
commit
d50d53f31d
4 changed files with 18 additions and 0 deletions
|
|
@ -27,6 +27,7 @@
|
|||
- API: Introduction of `m.redraw.sync()` ([#1592](https://github.com/MithrilJS/mithril.js/pull/1592))
|
||||
- API: Event handlers may also be objects with `handleEvent` methods ([#1939](https://github.com/MithrilJS/mithril.js/issues/1939)).
|
||||
- API: `m.route.link` accepts an optional `options` object ([#1930](https://github.com/MithrilJS/mithril.js/pull/1930))
|
||||
- API: `m.request` supports `timeout` as attr - ([#1966](https://github.com/MithrilJS/mithril.js/pull/1966))
|
||||
|
||||
#### Ospec improvements:
|
||||
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ Argument | Type | Required | Descr
|
|||
`options.user` | `String` | No | A username for HTTP authorization. Defaults to `undefined`.
|
||||
`options.password` | `String` | No | A password for HTTP authorization. Defaults to `undefined`. This option is provided for `XMLHttpRequest` compatibility, but you should avoid using it because it sends the password in plain text over the network.
|
||||
`options.withCredentials` | `Boolean` | No | Whether to send cookies to 3rd party domains. Defaults to `false`
|
||||
`options.timeout` | `Number` | No | The amount of milliseconds a request can take before automatically being [terminated](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/timeout). Defaults to `undefined`.
|
||||
`options.config` | `xhr = Function(xhr)` | No | Exposes the underlying XMLHttpRequest object for low-level configuration. Defaults to the [identity function](https://en.wikipedia.org/wiki/Identity_function).
|
||||
`options.headers` | `Object` | No | Headers to append to the request before sending it (applied right before `options.config`).
|
||||
`options.type` | `any = Function(any)` | No | A constructor to be applied to each object in the response. Defaults to the [identity function](https://en.wikipedia.org/wiki/Identity_function).
|
||||
|
|
|
|||
|
|
@ -75,6 +75,8 @@ module.exports = function($window, Promise) {
|
|||
}
|
||||
if (args.withCredentials) xhr.withCredentials = args.withCredentials
|
||||
|
||||
if (args.timeout) xhr.timeout = args.timeout
|
||||
|
||||
for (var key in args.headers) if ({}.hasOwnProperty.call(args.headers, key)) {
|
||||
xhr.setRequestHeader(key, args.headers[key])
|
||||
}
|
||||
|
|
|
|||
|
|
@ -435,6 +435,20 @@ o.spec("xhr", function() {
|
|||
done()
|
||||
})
|
||||
})
|
||||
o("set timeout to xhr instance", function() {
|
||||
mock.$defineRoutes({
|
||||
"GET /item": function() {
|
||||
return {status: 200, responseText: ''}
|
||||
}
|
||||
})
|
||||
return xhr({
|
||||
method: "GET", url: "/item",
|
||||
timeout: 42,
|
||||
config: function(xhr) {
|
||||
o(xhr.timeout).equals(42)
|
||||
}
|
||||
})
|
||||
})
|
||||
/*o("data maintains after interpolate", function() {
|
||||
mock.$defineRoutes({
|
||||
"PUT /items/:x": function() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue