Skip to content

Commit c85473e

Browse files
guymerssjrd
authored andcommitted
Add types for AbortController (#328)
1 parent f97fd58 commit c85473e

File tree

2 files changed

+73
-4
lines changed

2 files changed

+73
-4
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package org.scalajs.dom.experimental
2+
3+
import org.scalajs.dom.raw.EventTarget
4+
5+
import scala.scalajs.js
6+
import scala.scalajs.js.annotation.JSGlobal
7+
8+
/**
9+
* The AbortController interface represents a controller object that allows you
10+
* to abort one or more DOM requests as and when desired.
11+
*
12+
* MDN
13+
*/
14+
@js.native
15+
@JSGlobal
16+
class AbortController() extends js.Object {
17+
18+
/**
19+
* Returns a AbortSignal object instance, which can be used to communicate
20+
* with/abort a DOM request
21+
*
22+
* MDN
23+
*/
24+
val signal: AbortSignal = js.native
25+
26+
/**
27+
* Aborts a DOM request before it has completed. This is able to abort fetch
28+
* requests, consumption of any response Body, and streams.
29+
*
30+
* MDN
31+
*/
32+
def abort(): Unit = js.native
33+
}
34+
35+
/**
36+
* The AbortSignal interface represents a signal object that allows you to
37+
* communicate with a DOM request (such as a Fetch) and abort it if required
38+
* via an AbortController object.
39+
*
40+
* MDN
41+
*/
42+
@js.native
43+
trait AbortSignal extends EventTarget {
44+
45+
/**
46+
* A Boolean that indicates whether the request(s) the signal is
47+
* communicating with is/are aborted (true) or not (false).
48+
*
49+
* MDN
50+
*/
51+
def aborted: Boolean = js.native
52+
53+
/**
54+
* Invoked when an abort event fires, i.e. when the DOM request(s) the signal
55+
* is communicating with is/are aborted.
56+
*
57+
* MDN
58+
*/
59+
var onabort: js.Function0[Any] = js.native
60+
}

src/main/scala/org/scalajs/dom/experimental/Fetch.scala

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ class Request(input: RequestInfo, init: RequestInit = null) extends js.Object {
6868
def redirect: RequestRedirect = js.native
6969

7070
def integrity: String = js.native //should be DOMString
71+
72+
def keepalive: Boolean = js.native
73+
74+
def signal: AbortSignal = js.native
7175
}
7276

7377
object RequestInit {
@@ -88,6 +92,7 @@ object RequestInit {
8892
* //todo: it would help a lot if there were a way to make this fully type safe
8993
*/
9094
@inline
95+
@deprecated("use `new RequestInit {}` instead", "0.9.7")
9196
def apply(method: js.UndefOr[HttpMethod] = js.undefined,
9297
headers: js.UndefOr[HeadersInit] = js.undefined,
9398
body: js.UndefOr[BodyInit] = js.undefined,
@@ -114,8 +119,8 @@ object RequestInit {
114119
set("referrerPolicy", referrerPolicy)
115120
set("mode", mode)
116121
set("credentials", credentials)
117-
set("requestCache", requestCache)
118-
set("requestRedirect", requestRedirect)
122+
set("cache", requestCache)
123+
set("redirect", requestRedirect)
119124
set("integrity", integrity)
120125
set("window", window)
121126

@@ -143,12 +148,16 @@ trait RequestInit extends js.Object {
143148

144149
var credentials: js.UndefOr[RequestCredentials]
145150

146-
var requestCache: js.UndefOr[RequestCache]
151+
var cache: js.UndefOr[RequestCache]
147152

148-
var requestRedirect: js.UndefOr[RequestRedirect]
153+
var redirect: js.UndefOr[RequestRedirect]
149154

150155
var integrity: js.UndefOr[String]
151156

157+
var keepalive: js.UndefOr[Boolean]
158+
159+
var signal: js.UndefOr[AbortSignal]
160+
152161
/**
153162
* The whatwg spec section on [[https://fetch.spec.whatwg.org/#requestinit RequestInit dictionary]]
154163
* has a comment that states that this value "can only be set to null".

0 commit comments

Comments
 (0)