Skip to content

Commit eb09404

Browse files
authored
Merge pull request #458 from sjrd/cleanups
Cleanups, part 1
2 parents 159bab0 + a327899 commit eb09404

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+49277
-48825
lines changed

api-reports/2_12.txt

+23,858-23,809
Large diffs are not rendered by default.

api-reports/2_13.txt

+23,858-23,809
Large diffs are not rendered by default.

example/src/main/scala/example/Example.scala

+16-28
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package example
22

3+
import scala.scalajs.js
34
import scala.scalajs.js.annotation._
45

56
import org.scalajs.dom
@@ -125,21 +126,25 @@ object EventHandler{
125126
}
126127
}
127128

128-
@JSExportTopLevel("ExampleXMLHttpRequest")
129-
object XMLHttpRequest{
129+
@JSExportTopLevel("ExampleFetch")
130+
object Fetch {
130131
@JSExport
131132
def main(pre: html.Pre) = {
132-
val xhr = new dom.XMLHttpRequest()
133-
xhr.open("GET",
133+
import scala.concurrent
134+
.ExecutionContext
135+
.Implicits
136+
.global
137+
import js.Thenable.Implicits._
138+
val url =
134139
"https://www.boredapi.com/api/activity"
135-
)
136-
xhr.onload = { (e: dom.Event) =>
137-
if (xhr.status == 200) {
138-
pre.textContent =
139-
xhr.responseText
140-
}
140+
val responseText = for {
141+
response <- dom.fetch(url)
142+
text <- response.text()
143+
} yield {
144+
text
141145
}
142-
xhr.send()
146+
for (text <- responseText)
147+
pre.textContent = text
143148
}
144149
}
145150

@@ -162,20 +167,3 @@ object Websocket {
162167
}
163168
}
164169
}
165-
166-
@JSExportTopLevel("ExampleAjaxExtension")
167-
object AjaxExtension {
168-
@JSExport
169-
def main(pre: html.Pre) = {
170-
import dom.ext.Ajax
171-
import scala.concurrent
172-
.ExecutionContext
173-
.Implicits
174-
.global
175-
val url =
176-
"https://www.boredapi.com/api/activity"
177-
Ajax.get(url).foreach { case xhr =>
178-
pre.textContent = xhr.responseText
179-
}
180-
}
181-
}

readme/Index.scalatex

+4-23
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@
115115
autorun=true
116116
)
117117

118-
@sect{dom.XMLHttpRequest}
118+
@sect{dom.Fetch}
119119
@pair(
120-
"XMLHttpRequest",
120+
"Fetch",
121121
Seq(
122122
pre("output")
123123
)
@@ -145,38 +145,19 @@
145145
@li
146146
Deprecated properties/methods/types will not be present.
147147
@li
148-
IE-only, Chrome-only, FF-only, and in general browser-specific attributes will only be found under the @hl.scala{experimental} package.
148+
IE-only, Chrome-only, FF-only, and in general browser-specific attributes will typically not be present.
149149
@li
150150
The name of a Scala type should map directly to the name of the corresponding Javascript type.
151151
@li
152152
Any type which is a Javascript type (e.g. you can @hl.scala{instanceof} in javascript) should be a Scala @hl.scala{class}; any other interface which isn't a Javascript type should be a @hl.scala{trait}.
153153
@li
154154
Read-only members should be @hl.scala{def}, and not-directly-instantiable classes should have @hl.scala{private} constructors.
155155

156-
@sect{Extensions}
157-
158-
@p
159-
Apart from @hl.scala{Color}, Scala-js-dom contains some useful helpers and implicit classes in @hl.scala{org.scalajs.dom.ext} that serve no purpose other than to make your use of the DOM more pleasant.
160-
161-
@p
162-
Examples include the @hl.scala{Ajax.get} and @hl.scala{Ajax.post} methods which let you avoid messing with @hl.scala{dom.XMLHttpRequest} directly, or @hl.scala{KeyCodes} which provides a nice list of the keycodes that result from pressing various keys on the keyboard.
163-
@pair(
164-
"AjaxExtension",
165-
Seq(
166-
pre("output")
167-
)
168-
)
169-
170-
@p
171-
See also @a("roll", href:="https://github.com/lihaoyi/roll") (@a("live demo", href:="http://lihaoyi.github.io/roll/")) and @a("scala-js-games", href:="https://github.com/lihaoyi/scala-js-games") for an example of its use. @a("Scala-js-fiddle", href:="http://www.scala-js-fiddle.com/") also contains a pile of @a("fun examples", href:="(http://www.scala-js-fiddle.com/gist/9405209/Oscilloscope.scala") that demonstrate its usage. Pull requests/forks are welcome!
172-
173156
@sect{Contributing}
174157
@p
175-
Scala-js-dom is a work in progress. The current code base is a hodgepodge of auto-generated/scraped/hand-tweaked code, and is full of rough edges. If you see something that you think can be improved, feel free to send a pull request. These could include:
158+
The DOM API is always evolving, and scala-js-dom is a hodgepodge of auto-generated/scraped/hand-tweaked code full of rough edges. If you see something that you think can be improved, feel free to send a pull request. These could include:
176159
@ul
177160
@li
178161
Improved doc-comments; who doesn't love better docs?
179162
@li
180163
Missing methods/properties/classes; send the PR adding it in including it together with a link to an authoritative source (e.g. MDN) and it should get merged.
181-
@li
182-
Additional extensions (in @hl.scala{org.scalajs.dom.ext}). These currently represent an arbitrary collection of helpers that have been needed so far. If there's some implicit that you find you need and you think other people will to, send a pull request and we can talk about it.

src/main/scala-new-collections/org/scalajs/dom/ext/NamedNodeMapMap.scala renamed to src/main/scala-new-collections/org/scalajs/dom/NamedNodeMapMap.scala

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
package org.scalajs.dom.ext
1+
package org.scalajs.dom
22

3-
import org.scalajs.dom._
43
import scala.collection.mutable
54

6-
class NamedNodeMapMap private[ext] (namedNodeMap: NamedNodeMap)
5+
private[dom] class NamedNodeMapMap(namedNodeMap: NamedNodeMap)
76
extends mutable.Map[String, Attr] {
87
self =>
98

src/main/scala-old-collections/org/scalajs/dom/ext/NamedNodeMapMap.scala renamed to src/main/scala-old-collections/org/scalajs/dom/NamedNodeMapMap.scala

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
package org.scalajs.dom.ext
1+
package org.scalajs.dom
22

3-
import org.scalajs.dom._
43
import scala.collection.mutable
54

6-
class NamedNodeMapMap private[ext] (namedNodeMap: NamedNodeMap)
5+
private[dom] class NamedNodeMapMap(namedNodeMap: NamedNodeMap)
76
extends mutable.Map[String, Attr] {
87
self =>
98

src/main/scala/org/scalajs/dom/experimental/AbortController.scala renamed to src/main/scala/org/scalajs/dom/AbortController.scala

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
package org.scalajs.dom.experimental
1+
package org.scalajs.dom
22

3-
import org.scalajs.dom.raw.EventTarget
43
import scala.scalajs.js
54
import scala.scalajs.js.annotation.JSGlobal
65

src/main/scala/org/scalajs/dom/raw/Audio.scala renamed to src/main/scala/org/scalajs/dom/Audio.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Everything else is under the MIT License
88
* http://opensource.org/licenses/MIT
99
*/
10-
package org.scalajs.dom.raw
10+
package org.scalajs.dom
1111

1212
import org.scalajs.dom.experimental.mediastream.MediaStream
1313
import scala.scalajs.js

src/main/scala/org/scalajs/dom/raw/Css.scala renamed to src/main/scala/org/scalajs/dom/CSSTypes.scala

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Everything else is under the MIT License
88
* http://opensource.org/licenses/MIT
99
*/
10-
package org.scalajs.dom.raw
10+
package org.scalajs.dom
1111

1212
import scala.scalajs.js
1313
import scala.scalajs.js.annotation._
@@ -501,7 +501,9 @@ class CSSPageRule extends CSSRule {
501501
*/
502502
@js.native
503503
@JSGlobal
504-
class CSSRuleList extends DOMList[CSSRule]
504+
class CSSRuleList private[this] () extends DOMList[CSSRule] {
505+
def item(index: Int): CSSRule = js.native
506+
}
505507

506508
/**
507509
* The CSSKeyframesRule interface describes an object representing a complete set
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package org.scalajs.dom
2+
3+
import org.scalajs.dom
4+
5+
/**
6+
* Short aliases of all the dom.CSSThing classes
7+
*/
8+
@deprecated("directly use the dom.CSS* types and values instead", "2.0.0")
9+
object DeprecatedCSSAliases {
10+
@deprecated("use dom.CSS instead", "2.0.0")
11+
@inline def CSS = dom.CSS
12+
@deprecated("use dom.FontFaceRule instead", "2.0.0")
13+
type FontFaceRule = CSSFontFaceRule
14+
@deprecated("use dom.ImportRule instead", "2.0.0")
15+
type ImportRule = CSSImportRule
16+
@deprecated("use dom.KeyframeRule instead", "2.0.0")
17+
type KeyframeRule = CSSKeyframeRule
18+
@deprecated("use dom.MediaRule instead", "2.0.0")
19+
type MediaRule = CSSMediaRule
20+
@deprecated("use dom.NamespaceRule instead", "2.0.0")
21+
type NamespaceRule = CSSNamespaceRule
22+
@deprecated("use dom.PageRule instead", "2.0.0")
23+
type PageRule = CSSPageRule
24+
@deprecated("use dom.Rule instead", "2.0.0")
25+
type Rule = CSSRule
26+
@deprecated("use dom.Rule instead", "2.0.0")
27+
@inline def Rule = CSSRule
28+
@deprecated("use dom.RuleList instead", "2.0.0")
29+
type RuleList = CSSRuleList
30+
@deprecated("use dom.StyleDeclaration instead", "2.0.0")
31+
type StyleDeclaration = CSSStyleDeclaration
32+
@deprecated("use dom.StyleSheet instead", "2.0.0")
33+
type StyleSheet = CSSStyleSheet
34+
@deprecated("use dom.StyleRule instead", "2.0.0")
35+
type StyleRule = CSSStyleRule
36+
}

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

+1-14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
package org.scalajs.dom.experimental
1+
package org.scalajs.dom
22

3-
import org.scalajs.dom.Blob
4-
import org.scalajs.dom.raw.FormData
53
import scala.scalajs.js
64
import scala.scalajs.js.annotation._
75
import scala.scalajs.js.typedarray.{ArrayBuffer, Uint8Array}
@@ -183,17 +181,6 @@ trait ResponseInit extends js.Object {
183181
var headers: HeadersInit
184182
}
185183

186-
object ResponseInit {
187-
def apply(_status: Int = 200, _statusText: ByteString = "OK",
188-
_headers: HeadersInit = js.Dictionary[String]()): ResponseInit = {
189-
new ResponseInit {
190-
var status = _status
191-
var statusText = _statusText
192-
var headers = _headers
193-
}
194-
}
195-
}
196-
197184
/**
198185
* See [[https://fetch.spec.whatwg.org/#body body interface]] in whatwg Fetch spec.
199186
*

src/main/scala/org/scalajs/dom/raw/Html.scala renamed to src/main/scala/org/scalajs/dom/HTMLTypes.scala

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Everything else is under the MIT License
88
* http://opensource.org/licenses/MIT
99
*/
10-
package org.scalajs.dom.raw
10+
package org.scalajs.dom
1111

1212
import org.scalajs.dom.experimental.mediastream.{MediaSource, MediaStream}
1313
import scala.scalajs.js
@@ -1161,7 +1161,8 @@ abstract class HTMLMenuElement extends HTMLElement {
11611161
*/
11621162
@js.native
11631163
@JSGlobal
1164-
abstract class HTMLCollection extends DOMList[Element] {
1164+
class HTMLCollection private[this] () extends DOMList[Element] {
1165+
def item(index: Int): Element = js.native
11651166

11661167
/**
11671168
* Returns the specific node whose ID or, as a fallback, name matches the string

src/main/scala/org/scalajs/dom/raw/Idb.scala renamed to src/main/scala/org/scalajs/dom/IDBTypes.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Everything else is under the MIT License
88
* http://opensource.org/licenses/MIT
99
*/
10-
package org.scalajs.dom.raw
10+
package org.scalajs.dom
1111

1212
import scala.scalajs.js
1313
import scala.scalajs.js.annotation._

src/main/scala/org/scalajs/dom/ext/KeyValue.scala renamed to src/main/scala/org/scalajs/dom/KeyboardEventConstants.scala

+83-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.scalajs.dom.ext
1+
package org.scalajs.dom
22

33
/**
44
* The KeyboardEvent.key attribute of an event must always contain one of these control key or character values (even if
@@ -738,3 +738,85 @@ object KeyValue {
738738
final val ZoomToggle = "ZoomToggle"
739739
}
740740
}
741+
742+
/**
743+
* A list of the codes returned by KeyEvents.
744+
*/
745+
object KeyCode {
746+
final val Backspace = 8
747+
final val Tab = 9
748+
final val Enter = 13
749+
final val Shift = 16
750+
final val Ctrl = 17
751+
final val Alt = 18
752+
final val Pause = 19
753+
final val CapsLock = 20
754+
final val Escape = 27
755+
final val Space = 32
756+
final val PageUp = 33
757+
final val PageDown = 34
758+
final val End = 35
759+
final val Home = 36
760+
final val Left = 37
761+
final val Up = 38
762+
final val Right = 39
763+
final val Down = 40
764+
final val Insert = 45
765+
final val Delete = 46
766+
final val Num0 = 48
767+
final val Num1 = 49
768+
final val Num2 = 50
769+
final val Num3 = 51
770+
final val Num4 = 52
771+
final val Num5 = 53
772+
final val Num6 = 54
773+
final val Num7 = 55
774+
final val Num8 = 56
775+
final val Num9 = 57
776+
final val A = 65
777+
final val B = 66
778+
final val C = 67
779+
final val D = 68
780+
final val E = 69
781+
final val F = 70
782+
final val G = 71
783+
final val H = 72
784+
final val I = 73
785+
final val J = 74
786+
final val K = 75
787+
final val L = 76
788+
final val M = 77
789+
final val N = 78
790+
final val O = 79
791+
final val P = 80
792+
final val Q = 81
793+
final val R = 82
794+
final val S = 83
795+
final val T = 84
796+
final val U = 85
797+
final val V = 86
798+
final val W = 87
799+
final val X = 88
800+
final val Y = 89
801+
final val Z = 90
802+
final val F1 = 112
803+
final val F2 = 113
804+
final val F3 = 114
805+
final val F4 = 115
806+
final val F5 = 116
807+
final val F6 = 117
808+
final val F7 = 118
809+
final val F8 = 119
810+
final val F9 = 120
811+
final val F10 = 121
812+
final val F11 = 122
813+
final val F12 = 123
814+
}
815+
816+
/** Aliases for DOM_KEY_LOCATION_* constants from [[KeyboardEvent]] */
817+
object KeyLocation {
818+
final val Standard = KeyboardEvent.DOM_KEY_LOCATION_STANDARD
819+
final val Left = KeyboardEvent.DOM_KEY_LOCATION_LEFT
820+
final val Right = KeyboardEvent.DOM_KEY_LOCATION_RIGHT
821+
final val NumPad = KeyboardEvent.DOM_KEY_LOCATION_NUMPAD
822+
}

src/main/scala/org/scalajs/dom/experimental/Notification.scala renamed to src/main/scala/org/scalajs/dom/Notification.scala

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
package org.scalajs.dom.experimental
1+
package org.scalajs.dom
22

3-
import org.scalajs.dom.raw.EventTarget
43
import scala.scalajs.js
54
import scala.scalajs.js.annotation._
65

src/main/scala/org/scalajs/dom/raw/OffscreenCanvas.scala renamed to src/main/scala/org/scalajs/dom/OffscreenCanvas.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.scalajs.dom.raw
1+
package org.scalajs.dom
22

33
import scala.scalajs.js
44
import scala.scalajs.js.annotation.JSGlobal

0 commit comments

Comments
 (0)