-
Notifications
You must be signed in to change notification settings - Fork 162
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
Performance api improvements #709
Conversation
@@ -15,7 +15,7 @@ import scala.scalajs.js.annotation._ | |||
*/ | |||
@js.native | |||
@JSGlobal | |||
class Performance extends js.Object { | |||
class Performance private[this] () extends js.Object { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You cannot create objects of type Performance
. Is this the correct way to forbid it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I think we do this in other places as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is correct.
@@ -15,7 +15,7 @@ import scala.scalajs.js.annotation._ | |||
*/ | |||
@js.native | |||
@JSGlobal | |||
class Performance extends js.Object { | |||
class Performance private[this] () extends js.Object { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I think we do this in other places as well.
@@ -28,7 +28,7 @@ class Performance extends js.Object { | |||
*/ | |||
def timing: PerformanceTiming = js.native | |||
|
|||
def getEntriesByType(entryType: String): js.Dynamic = js.native | |||
def getEntriesByType(entryType: String): js.Array[PerformanceEntry] = js.native |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since there are only a limited set of values that can be passed as an entryType
I wonder if we should create a specific type for it.
https://developer.mozilla.org/en-US/docs/Web/API/PerformanceEntry/entryType
E.g. like InputType
.
https://github.com/scala-js/scala-js-dom/blob/1a944e4863aaf52694e29e38fb2a174f351f2ceb/dom/src/main/scala-3/org/scalajs/dom/InputType.scala
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, maybe I was wrong 😅
As the list of supported entries varies per browser and is evolving, this property allows web developers to check which are available.
https://developer.mozilla.org/en-US/docs/Web/API/PerformanceObserver/supportedEntryTypes
/** The first timestamp recorded for this performance entry. The meaning of this property depends on the value of this | ||
* entry's [[entryType]]. | ||
*/ | ||
def startTime: Double = js.native |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The spec mentions that this returns a "DOMHighResTimestamp" https://w3c.github.io/performance-timeline/#dom-performanceentry
Is it worth it to make a type for https://www.w3.org/TR/hr-time-3/#dom-domhighrestimestamp
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably don't want an opaque type, since then you can't do numerical ops on it.
We could make a transparent type alias e.g. type DOMHighRestTimestamp = Double
but it's a coin flip whether its documentation or obfuscation 😂
These are some improvements to the Performance API after testing it for a while