Repository navigation
1.2.0 -> 2.x migration guide #627
Replies: 7 comments 5 replies
Example migration:import org.scalajs.dom
// Before (deprecated)
val response = dom.experimental.ResponseInit(myStatus, myStatusText, myHeaders)
// After
val response = new dom.ResponseInit {
status = myStatus
statusText = myStatusText
headers = myHeaders
}Note: this example has been updated to reflect corrections made in v2.1.0. For discussion see #624. |
|
(I was using // before
val seqOfFiles = new EasySeq[File](el.ref.files.length, el.ref.files.apply).toSeq
// after
val seqOfFiles = el.ref.files.toSeq |
|
|
|
|
|
JS-native traits that don't have their vars implemented should be initialized as noted above: val response = new dom.ResponseInit {
var status = myStatus
var statusText = myStatusText
var headers = myHeaders
}There are traits that have the vars initialized. For example, trait MutationObserverInit extends js.Object {
var childList: js.UndefOr[Boolean] = js.undefined
// ...These are intended to be initialized the following way: new MutationObserverInit {
this.childList = someChildList
}Note that we're not overriding the var in this case, rather we're imperatively re-assigning it in the constructor. (thanks, Sébastien, for pointing this out!) (see #624) |
|
Beforeimport org.scalajs.dom.ext.Ajax
Ajax.post(
url = "url",
headers = Map("header" -> "value", ...),
data = "body"
)Afterimport org.scalajs.dom.{Fetch, HttpMethod, RequestInit}
Fetch.fetch(
"url",
new RequestInit {
method = HttpMethod.POST
headers = scalajs.js.Dictionary("header" -> "value", ...)
body = "body"
}
).toFuture |
|
There used to be a package object |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
CrossVersion.for3Use2_13As scala-js-dom v2.x publishes a Scala 3 artifact, this setting is no longer necessary. Failing to remove this from your build.sbt will cause your library to become binary-incompatible with other libraries correctly depending on scala-js-dom v2.x.
Big picture
To address the deprecation warnings:
dom.raw.*,dom.experimental.*anddom.crypto.*sub-packages withdom.*. Nearly everything is indom.*now except forintlandwebgl.new-based constructors instead ofapply-based constructors.You can also automate some, hopefully the majority, of your migration by running this quick script:
Additional details
Please comment with your notes and tips for a successful migration! For questions/issues with migration, please create an issue instead.
All reactions