Skip to content
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

Updates MediaQueryList to extend EventTarget #724

Merged
merged 7 commits into from
Sep 5, 2022

Conversation

mabasic
Copy link
Contributor

@mabasic mabasic commented Aug 31, 2022

It would seem that MediaQueryList was outdated, so I updated it according to the MDN: https://developer.mozilla.org/en-US/docs/Web/API/MediaQueryList

Changes

The main difference is that now MediaQueryList extends EventTarget which allows for addEventListener method and others. Deprecated addListener and removeListener methods. I hope that I got the version number for @deprecated right.

Issue

I could not get the compiler to compile with addListener because it expected MediaQueryListListener. Don't know if this has ever worked for someone. I am very new to scala and maybe I don't know how it was supposed to work.

Before

val prefersDark: MediaQueryList = window.matchMedia("(prefers-color-scheme: dark)")

prefersDark.addListener({ (e: MediaQueryList) =>
  println(e.matches)
})

would complain about function: Unit not being of type MediaQueryListListener.

After

val prefersDark: MediaQueryList = window.matchMedia("(prefers-color-scheme: dark)")

prefersDark.addEventListener({ (e: MediaQueryList) =>
    println(e.matches)
})

should be good now.

  • run sbt prePR ✔ (done)
Index.scalatex:43:6: type mismatch;
[error]  found   : scalatex.site.Section.Proxy
[error]  required: scalatags.Text.all.Frag
[error]     (which expands to)  scalatags.generic.Frag[scalatags.text.Builder,String]
[error] @sect{scala-js-dom}
[error]      ^
[error] one error found
[error] (readme / Compile / compileIncremental) Compilation failed
[error] Total time: 117 s (01:57), completed 31. kol 2022. 11:17:41
[IJ]root>

Not sure if this was my fault?

  • commit changes to api-reports ❌ (what does this mean?)

@mabasic mabasic changed the title feat(mediaquerylist): updates MediaQueryList to extend EventTarget Updates MediaQueryList to extend EventTarget Aug 31, 2022
Copy link
Member

@armanbilge armanbilge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! Just a couple small changes, but looks good to me.

However, there seems to be an issue with the API reports. Try running prePR again and committing them. If that doesn't work I will push a fix for you.

api-reports/2_12.txt Outdated Show resolved Hide resolved
api-reports/2_12.txt Outdated Show resolved Hide resolved
dom/src/main/scala/org/scalajs/dom/MediaQueryList.scala Outdated Show resolved Hide resolved
dom/src/main/scala/org/scalajs/dom/MediaQueryList.scala Outdated Show resolved Hide resolved
dom/src/main/scala/org/scalajs/dom/MediaQueryList.scala Outdated Show resolved Hide resolved
@mabasic
Copy link
Contributor Author

mabasic commented Aug 31, 2022

@armanbilge I have commited the changes you suggested, thank you for that. I've also reverted the commit regarding 2_12.txt.

When I run prePR locally this is what I get:

PS C:\Users\mario\code\src\github.com\mabasic\scala-js-dom> sbt
[info] welcome to sbt 1.7.1 (AdoptOpenJDK Java 1.8.0_292)
[info] loading global plugins from C:\Users\mario\.sbt\1.0\plugins
[info] loading settings for project scala-js-dom-build from plugins.sbt ...
[info] loading project definition from C:\Users\mario\code\src\github.com\mabasic\scala-js-dom\project
[info] compiling 3 Scala sources to C:\Users\mario\code\src\github.com\mabasic\scala-js-dom\project\target\scala-2.12\sbt-1.0\classes ...
[info] loading settings for project root from build.sbt,prePR.sbt,scalafix.sbt ...
[info] resolving key references (11842 settings) ...
[info] set current project to Scala.js DOM (in build file:/C:/Users/mario/code/src/github.com/mabasic/scala-js-dom/)
[info] sbt server started at local:sbt-server-bd5365f774a0f0e828ad
[info] started sbt server
root> prePR
[info] Setting Scala version to 2.11.12 on 9 projects.
[info] Excluded 1 projects, run ++ 2.11.12 -v for more details.
[info] Reapplying settings...
[info] set current project to Scala.js DOM (in build file:/C:/Users/mario/code/src/github.com/mabasic/scala-js-dom/)
[info] scalafmt: Formatting 680 Scala sources (C:\Users\mario\code\src\github.com\mabasic\scala-js-dom\dom)...
[info] compiling 730 Scala sources to C:\Users\mario\code\src\github.com\mabasic\scala-js-dom\dom\target\scala-2.11\classes ...
[warn] C:\Users\mario\code\src\github.com\mabasic\scala-js-dom\dom\src\main\scala\org\scalajs\dom\experimental\intl\package.scala:18:34: object CollatorOptions in package intl is deprecated: all the members of CollatorOptions are deprecated
[warn]   val CollatorOptions = dom.intl.CollatorOptions
[warn]                                  ^
[warn] C:\Users\mario\code\src\github.com\mabasic\scala-js-dom\dom\src\main\scala\org\scalajs\dom\experimental\intl\package.scala:30:40: object DateTimeFormatOptions in package intl is deprecated: all members of DateTimeFormatOptions are deprecated
[warn]   val DateTimeFormatOptions = dom.intl.DateTimeFormatOptions
[warn]                                        ^
[warn] C:\Users\mario\code\src\github.com\mabasic\scala-js-dom\dom\src\main\scala\org\scalajs\dom\experimental\intl\package.scala:42:38: object NumberFormatOptions in package intl is deprecated: all the members of NumberFormatOptions are deprecated
[warn]   val NumberFormatOptions = dom.intl.NumberFormatOptions
[warn]                                      ^
[warn] C:\Users\mario\code\src\github.com\mabasic\scala-js-dom\dom\src\main\scala\org\scalajs\dom\experimental\mediastream\package.scala:35:29: object MediaDeviceInfo in package dom is deprecated: all the members of MediaDeviceInfo are deprecated
[warn]   val MediaDeviceInfo = dom.MediaDeviceInfo
[warn]                             ^
[warn] C:\Users\mario\code\src\github.com\mabasic\scala-js-dom\dom\src\main\scala\org\scalajs\dom\experimental\mediastream\package.scala:59:36: object MediaStreamConstraints in package dom is deprecated: all the members of MediaStreamConstraints are deprecated
[warn]   val MediaStreamConstraints = dom.MediaStreamConstraints
[warn]                                    ^
[warn] C:\Users\mario\code\src\github.com\mabasic\scala-js-dom\dom\src\main\scala\org\scalajs\dom\experimental\mediastream\package.scala:65:30: object MediaStreamTrack in package dom is deprecated: all the members of MediaStreamTrack are deprecated
[warn]   val MediaStreamTrack = dom.MediaStreamTrack
[warn]                              ^
[warn] C:\Users\mario\code\src\github.com\mabasic\scala-js-dom\dom\src\main\scala\org\scalajs\dom\experimental\mediastream\package.scala:83:37: object MediaTrackConstraintSet in package dom is deprecated: all the members of MediaTrackConstraintSet are deprecated
[warn]   val MediaTrackConstraintSet = dom.MediaTrackConstraintSet
[warn]                                     ^
[warn] C:\Users\mario\code\src\github.com\mabasic\scala-js-dom\dom\src\main\scala\org\scalajs\dom\experimental\mediastream\package.scala:89:35: object MediaTrackConstraints in package dom is deprecated: all the members of MediaTrackConstraints are deprecated
[warn]   val MediaTrackConstraints = dom.MediaTrackConstraints
[warn]                                   ^
[warn] C:\Users\mario\code\src\github.com\mabasic\scala-js-dom\dom\src\main\scala\org\scalajs\dom\experimental\permissions\package.scala:30:34: object PermissionDescriptor in package dom is deprecated: all the members of PermissionDescriptor are deprecated
[warn]   val PermissionDescriptor = dom.PermissionDescriptor
[warn]                                  ^
[warn] C:\Users\mario\code\src\github.com\mabasic\scala-js-dom\dom\src\main\scala\org\scalajs\dom\experimental\permissions\package.scala:36:38: object PushPermissionDescriptor in package dom is deprecated: all the members of PushPermissionDescriptor are deprecated
[warn]   val PushPermissionDescriptor = dom.PushPermissionDescriptor
[warn]                                      ^
[warn] C:\Users\mario\code\src\github.com\mabasic\scala-js-dom\dom\src\main\scala\org\scalajs\dom\experimental\webrtc\package.scala:27:30: object RTCConfiguration in package dom is deprecated: all members of RTCConfiguration are deprecated
[warn]   val RTCConfiguration = dom.RTCConfiguration
[warn]                              ^
[warn] C:\Users\mario\code\src\github.com\mabasic\scala-js-dom\dom\src\main\scala\org\scalajs\dom\experimental\webrtc\package.scala:39:32: object RTCDataChannelInit in package dom is deprecated: all members of RTCDataChannelInit are deprecated
[warn]   val RTCDataChannelInit = dom.RTCDataChannelInit
[warn]                                ^
[warn] C:\Users\mario\code\src\github.com\mabasic\scala-js-dom\dom\src\main\scala\org\scalajs\dom\experimental\webrtc\package.scala:57:33: object RTCIceCandidateInit in package dom is deprecated: all members of RTCIceCandidateInit are deprecated
[warn]   val RTCIceCandidateInit = dom.RTCIceCandidateInit
[warn]                                 ^
[warn] C:\Users\mario\code\src\github.com\mabasic\scala-js-dom\dom\src\main\scala\org\scalajs\dom\experimental\webrtc\package.scala:78:26: object RTCIceServer in package dom is deprecated: all members of RTCIceServer are deprecated
[warn]   val RTCIceServer = dom.RTCIceServer
[warn]                          ^
[warn] C:\Users\mario\code\src\github.com\mabasic\scala-js-dom\dom\src\main\scala\org\scalajs\dom\experimental\webrtc\package.scala:90:34: object RTCIdentityAssertion in package dom is deprecated: all members of RTCPeerConnection are deprecated
[warn]   val RTCIdentityAssertion = dom.RTCIdentityAssertion
[warn]                                  ^
[warn] C:\Users\mario\code\src\github.com\mabasic\scala-js-dom\dom\src\main\scala\org\scalajs\dom\experimental\webrtc\package.scala:96:29: object RTCOfferOptions in package dom is deprecated: all members of RTCOfferOptions are deprecated
[warn]   val RTCOfferOptions = dom.RTCOfferOptions
[warn]                             ^
[warn] C:\Users\mario\code\src\github.com\mabasic\scala-js-dom\dom\src\main\scala\org\scalajs\dom\experimental\webrtc\package.scala:120:39: object RTCSessionDescriptionInit in package dom is deprecated: all members of RTCSessionDescriptionInit are deprecated
[warn]   val RTCSessionDescriptionInit = dom.RTCSessionDescriptionInit
[warn]                                       ^
[warn] 17 warnings found
[info] compiling 1 Scala source to C:\Users\mario\code\src\github.com\mabasic\scala-js-dom\example\target\scala-2.11\classes ...
[info] compiling 5 Scala sources to C:\Users\mario\code\src\github.com\mabasic\scala-js-dom\tests-shared\target\scala-2.11\classes ...
[info] compiling 1 Scala source to C:\Users\mario\code\src\github.com\mabasic\scala-js-dom\tests-node-jsdom\target\scala-2.11\test-classes ...
[info] compiling 7 Scala sources to C:\Users\mario\code\src\github.com\mabasic\scala-js-dom\tests-webworker\target\scala-2.11\classes ...
[info] compiling 1 Scala source to C:\Users\mario\code\src\github.com\mabasic\scala-js-dom\tests-firefox\target\scala-2.11\test-classes ...
[info] compiling 1 Scala source to C:\Users\mario\code\src\github.com\mabasic\scala-js-dom\tests-chrome\target\scala-2.11\test-classes ...
[success] Total time: 100 s (01:40), completed 31.08.2022. 22:49:11
[info] Setting Scala version to 2.12.15 on 10 projects.
[info] Reapplying settings...
[info] set current project to Scala.js DOM (in build file:/C:/Users/mario/code/src/github.com/mabasic/scala-js-dom/)
[info] compiling 4 Scala sources to C:\Users\mario\code\src\github.com\mabasic\scala-js-dom\scalafix\target\scala-2.12\classes ...
[info] Loading external rule(s) built against an old version of Scalafix (0.9.24).
[info] This might not be a problem, but in case you run into unexpected behavior, you
[info] should try a more recent version of the rules(s) if available. If that does
[info] not help, request the rule(s) maintainer to build against Scalafix 0.10.1
[info] or later, and downgrade Scalafix to 0.9.x (x>=24) for the time being.
[info]
[info] compiling 730 Scala sources to C:\Users\mario\code\src\github.com\mabasic\scala-js-dom\dom\target\scala-2.12\classes ...
[info] Running scalafix on 730 Scala sources
[info] Generating C:\Users\mario\code\src\github.com\mabasic\scala-js-dom\api-reports\2_12.txt
[info] scalafmt: Formatting 680 Scala sources (C:\Users\mario\code\src\github.com\mabasic\scala-js-dom\dom)...
[info] compiling 5 Scala sources to C:\Users\mario\code\src\github.com\mabasic\scala-js-dom\tests-shared\target\scala-2.12\classes ...
[info] compiling 1 Scala source to C:\Users\mario\code\src\github.com\mabasic\scala-js-dom\example\target\scala-2.12\classes ...
[info] compiling 1 Scala source to C:\Users\mario\code\src\github.com\mabasic\scala-js-dom\tests-node-jsdom\target\scala-2.12\test-classes ...
[info] compiling 7 Scala sources to C:\Users\mario\code\src\github.com\mabasic\scala-js-dom\tests-webworker\target\scala-2.12\classes ...
[info] compiling 1 Scala source to C:\Users\mario\code\src\github.com\mabasic\scala-js-dom\tests-chrome\target\scala-2.12\test-classes ...
[info] compiling 1 Scala source to C:\Users\mario\code\src\github.com\mabasic\scala-js-dom\tests-firefox\target\scala-2.12\test-classes ...
Generating Scalatex Sources...
[info] compiling 2 Scala sources to C:\Users\mario\code\src\github.com\mabasic\scala-js-dom\readme\target\scala-2.12\classes ...
[error] C:\Users\mario\code\src\github.com\mabasic\scala-js-dom\readme\Index.scalatex:43:6: type mismatch;
[error]  found   : scalatex.site.Section.Proxy
[error]  required: scalatags.Text.all.Frag
[error]     (which expands to)  scalatags.generic.Frag[scalatags.text.Builder,String]
[error] @sect{scala-js-dom}
[error]      ^
[error] one error found
[error] (readme / Compile / compileIncremental) Compilation failed
[error] Total time: 136 s (02:16), completed 31.08.2022. 22:51:29
root>

Maybe it fails to produce correct files because of the error? I am very much out of my scope here :/

@armanbilge
Copy link
Member

Thanks! One more thing I realized: we should probably deprecate MediaQueryListListener as well?

trait MediaQueryListListener extends js.Object {

Regarding the error ... I have a vague memory someone else on Windows had a similar problem. Let me see if I can find it.

@armanbilge
Copy link
Member

armanbilge commented Aug 31, 2022

Right, someone had the exact same problem in #628 (comment). I don't know what causes it 😕

@mabasic
Copy link
Contributor Author

mabasic commented Aug 31, 2022

Right, someone had the exact same problem in #628 (comment). I don't know what causes it 😕

@armanbilge Maybe this is the issue somehow: lihaoyi/Scalatex#69

I am using autocrlf = true in my git config which upon checkout converts files to crlf, and then on add it returns them to lf. Maybe I should try setting it to false, and then cloning the repo and running prePR.

@armanbilge
Copy link
Member

Nice find, I bet that's it!

@mabasic
Copy link
Contributor Author

mabasic commented Aug 31, 2022

Nice find, I bet that's it!

It would seem so. I got it working both on Windows and on WSL2 now. On Windows I had to set this in the .gitconfig file:

[core]
	autocrlf = false

on WSL2 it worked out of the box.

Maybe place a message somewhere stating that having LF line endings is a must in order for prePR to complete or just suggesting to users to set autocrlf = false on Windows.

I will drop these links here for future reference:

@mabasic
Copy link
Contributor Author

mabasic commented Aug 31, 2022

@armanbilge I've added api-reports now, can you take a look at this PR and let me know if there is more for me to do?

Copy link
Member

@armanbilge armanbilge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you very much!

I will update the contributor docs to mention the autocrlf = false thing, thank you so much for getting to the bottom of it. It is pretty annoying, actually in the long-run we have to replace the documentation framework anyway as scalatex is no longer maintained.

@mabasic
Copy link
Contributor Author

mabasic commented Sep 1, 2022

Usually, I would consider taking such a task to replace the documentation because I like seeing nice documentation, but I am currently trying to finish 4 other projects of mine. Maybe once I am done with those I could circle back to this, can't promise.

Do you know when the new release will happen or is there a way for me to use this branch in my project?

I come from PHP background and there we can specify the branch in this exact case where you can't wait for a release 😊. Is there something like this in scala/sbt?

@armanbilge
Copy link
Member

No problem, appreciate all your contributions :)

Do you know when the new release will happen or is there a way for me to use this branch in my project?

It may be a while, since I just released 2.3.0 yesterday 😅 the current release rate has been every few months, but I don't mind doing it sooner once some more changes have accumulated. Sorry, bad timing!

However, after I merge your PR there will be a snapshot release available which you can use immediately. I will merge your PR in a few days, just to give the other maintainers a chance to review it if they want. Snapshots are published here:

https://oss.sonatype.org/content/repositories/snapshots/org/scala-js/

Until then, you can run sbt publishLocal and it will publish the snapshot on your local machine.

There is one more option: since your change here is quite simple, in your own code you can just cast manually:

prefersDark.asInstanceOf[EventTarget].addEventListener { ...

@armanbilge armanbilge merged commit 8266cde into scala-js:main Sep 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants