-
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
Changes from 7 commits
6d6a3cd
38b8988
cbc769f
1ee7b40
12deff1
1066217
12eea31
ce8678d
b2d400b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ import scala.scalajs.js.annotation._ | |
*/ | ||
@js.native | ||
@JSGlobal | ||
class Performance extends js.Object { | ||
class Performance private[this] () extends js.Object { | ||
|
||
/** The Performance.navigation read-only property returns a PerformanceNavigation object representing the type of | ||
* navigation that occurs in the given browsing context, like the amount of redirections needed to fetch the | ||
|
@@ -28,29 +28,49 @@ class Performance extends js.Object { | |
*/ | ||
def timing: PerformanceTiming = js.native | ||
|
||
def getEntriesByType(entryType: String): js.Dynamic = js.native | ||
/** Returns an array of [[PerformanceEntry]] objects currently present in the performance timeline for a given type */ | ||
def getEntriesByType(entryType: String): js.Array[PerformanceEntry] = js.native | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 E.g. like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, maybe I was wrong 😅
https://developer.mozilla.org/en-US/docs/Web/API/PerformanceObserver/supportedEntryTypes |
||
|
||
/** Is a jsonizer returning a json object representing the Performance object. */ | ||
armanbilge marked this conversation as resolved.
Show resolved
Hide resolved
|
||
def toJSON(): js.Dynamic = js.native | ||
def toJSON(): js.Object = js.native | ||
|
||
@deprecated("No such API in the spec", "2.4.0") | ||
def getMeasures(measureName: String = js.native): js.Dynamic = js.native | ||
|
||
/** Removes all or specific [[PerformanceMark]] objects from the browser's performance timeline. */ | ||
def clearMarks(markName: String = js.native): Unit = js.native | ||
|
||
@deprecated("No such API in the spec", "2.4.0") | ||
def getMarks(markName: String = js.native): js.Dynamic = js.native | ||
|
||
/** Removes all performance entries with an `entryType` of "resource" from the browser's performance timeline and sets | ||
* the size of the performance resource data buffer to zero. | ||
*/ | ||
def clearResourceTimings(): Unit = js.native | ||
|
||
def mark(markName: String): Unit = js.native | ||
/** Creates a named [[PerformanceMark]] object representing a high resolution timestamp marker in the browser's | ||
* performance timeline. | ||
*/ | ||
def mark(markName: String): PerformanceMark = js.native | ||
|
||
def measure(measureName: String, startMarkName: String = js.native, endMarkName: String = js.native): Unit = js.native | ||
/** Creates a named [[PerformanceMeasure]] object representing a time measurement between two marks in the browser's | ||
* performance timeline. | ||
*/ | ||
def measure(measureName: String, startMarkName: String = js.native, | ||
endMarkName: String = js.native): PerformanceMeasure = js.native | ||
|
||
def getEntriesByName(name: String, entryType: String = js.native): js.Dynamic = js.native | ||
/** Returns an array of [[PerformanceEntry]] objects currently present in the performance timeline with the given name | ||
* and type. | ||
*/ | ||
def getEntriesByName(name: String, `type`: String = js.native): js.Array[PerformanceEntry] = js.native | ||
|
||
def getEntries(): js.Dynamic = js.native | ||
/** All [[PerformanceEntry]] objects currently present in the performance timeline. */ | ||
def getEntries(): js.Array[PerformanceEntry] = js.native | ||
|
||
/** Removes all or specific [[PerformanceMeasure]] objects from the browser's performance timeline. */ | ||
def clearMeasures(measureName: String = js.native): Unit = js.native | ||
|
||
/** sets the desired size of the browser's resource timing buffer which stores the "resource" performance entries. */ | ||
armanbilge marked this conversation as resolved.
Show resolved
Hide resolved
|
||
def setResourceTimingBufferSize(maxSize: Int): Unit = js.native | ||
|
||
/** Returns a DOMHighResTimeStamp representing the amount of milliseconds elapsed since the start of the navigation, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,14 +9,29 @@ package org.scalajs.dom | |
import scala.scalajs.js | ||
import scala.scalajs.js.annotation._ | ||
|
||
/** Encapsulates a single performance metric that is part of the browser's performance timeline. */ | ||
@js.native | ||
@JSGlobal | ||
class PerformanceEntry extends js.Object { | ||
|
||
/** The name for a performance entry. It acts as an identifier, but it does not have to be unique. The value depends | ||
* on the subclass. | ||
*/ | ||
def name: String = js.native | ||
|
||
/** 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 | ||
Comment on lines
+22
to
25
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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. |
||
|
||
/** The duration of the performance entry. The meaning of this property depends on the value of this entry's | ||
* [[entryType]]. | ||
*/ | ||
def duration: Int = js.native | ||
|
||
/** The type of performance metric that this entry represents. */ | ||
def entryType: String = js.native | ||
|
||
/** Returns a JSON representation of the [[PerformanceEntry]] object. */ | ||
def toJSON(): js.Object = 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.
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.