Skip to content

Add types for AbortController #328

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions src/main/scala/org/scalajs/dom/experimental/AbortController.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package org.scalajs.dom.experimental

import org.scalajs.dom.raw.EventTarget

import scala.scalajs.js
import scala.scalajs.js.annotation.JSGlobal

/**
* The AbortController interface represents a controller object that allows you
* to abort one or more DOM requests as and when desired.
*
* MDN
*/
@js.native
@JSGlobal
class AbortController() extends js.Object {

/**
* Returns a AbortSignal object instance, which can be used to communicate
* with/abort a DOM request
*
* MDN
*/
val signal: AbortSignal = js.native

/**
* Aborts a DOM request before it has completed. This is able to abort fetch
* requests, consumption of any response Body, and streams.
*
* MDN
*/
def abort(): Unit = js.native
}

/**
* The AbortSignal interface represents a signal object that allows you to
* communicate with a DOM request (such as a Fetch) and abort it if required
* via an AbortController object.
*
* MDN
*/
@js.native
trait AbortSignal extends EventTarget {

/**
* A Boolean that indicates whether the request(s) the signal is
* communicating with is/are aborted (true) or not (false).
*
* MDN
*/
def aborted: Boolean = js.native

/**
* Invoked when an abort event fires, i.e. when the DOM request(s) the signal
* is communicating with is/are aborted.
*
* MDN
*/
var onabort: js.Function0[Any] = js.native
}
17 changes: 13 additions & 4 deletions src/main/scala/org/scalajs/dom/experimental/Fetch.scala
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ class Request(input: RequestInfo, init: RequestInit = null) extends js.Object {
def redirect: RequestRedirect = js.native

def integrity: String = js.native //should be DOMString

def keepalive: Boolean = js.native

def signal: AbortSignal = js.native
}

object RequestInit {
Expand All @@ -88,6 +92,7 @@ object RequestInit {
* //todo: it would help a lot if there were a way to make this fully type safe
*/
@inline
@deprecated("use `new RequestInit {}` instead", "0.9.7")
def apply(method: js.UndefOr[HttpMethod] = js.undefined,
headers: js.UndefOr[HeadersInit] = js.undefined,
body: js.UndefOr[BodyInit] = js.undefined,
Expand All @@ -114,8 +119,8 @@ object RequestInit {
set("referrerPolicy", referrerPolicy)
set("mode", mode)
set("credentials", credentials)
set("requestCache", requestCache)
set("requestRedirect", requestRedirect)
set("cache", requestCache)
set("redirect", requestRedirect)
set("integrity", integrity)
set("window", window)

Expand Down Expand Up @@ -143,12 +148,16 @@ trait RequestInit extends js.Object {

var credentials: js.UndefOr[RequestCredentials]

var requestCache: js.UndefOr[RequestCache]
var cache: js.UndefOr[RequestCache]

var requestRedirect: js.UndefOr[RequestRedirect]
var redirect: js.UndefOr[RequestRedirect]

var integrity: js.UndefOr[String]

var keepalive: js.UndefOr[Boolean]

var signal: js.UndefOr[AbortSignal]

/**
* The whatwg spec section on [[https://fetch.spec.whatwg.org/#requestinit RequestInit dictionary]]
* has a comment that states that this value "can only be set to null".
Expand Down