-
Notifications
You must be signed in to change notification settings - Fork 194
Lib: add message event types and PerformanceObserver #1164
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
open! Import | ||
|
||
class type performanceObserverInit = | ||
object | ||
method entryTypes : Js.js_string Js.t Js.js_array Js.t Js.writeonly_prop | ||
end | ||
|
||
class type performanceEntry = | ||
object | ||
method name : Js.js_string Js.t Js.readonly_prop | ||
|
||
method entryType : Js.js_string Js.t Js.readonly_prop | ||
|
||
method startTime : float Js.readonly_prop | ||
|
||
method duration : float Js.readonly_prop | ||
end | ||
|
||
class type performanceObserverEntryList = | ||
object | ||
method getEntries : performanceEntry Js.t Js.js_array Js.t Js.meth | ||
end | ||
|
||
class type performanceObserver = | ||
object | ||
method observe : performanceObserverInit Js.t -> unit Js.meth | ||
|
||
method disconnect : unit Js.meth | ||
|
||
method takeRecords : performanceEntry Js.t Js.js_array Js.t Js.meth | ||
end | ||
|
||
let performanceObserver = Js.Unsafe.global##._PerformanceObserver | ||
|
||
let is_supported () = Js.Optdef.test performanceObserver | ||
|
||
let performanceObserver : | ||
( (performanceObserverEntryList Js.t -> performanceObserver Js.t -> unit) Js.callback | ||
-> performanceObserver Js.t) | ||
Js.constr = | ||
performanceObserver | ||
|
||
let observe ~entry_types ~f = | ||
let entry_types = entry_types |> List.map Js.string |> Array.of_list |> Js.array in | ||
let performance_observer_init : performanceObserverInit Js.t = Js.Unsafe.obj [||] in | ||
let () = performance_observer_init##.entryTypes := entry_types in | ||
let obs = new%js performanceObserver (Js.wrap_callback f) in | ||
let () = obs##observe performance_observer_init in | ||
obs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
(** PerformanceObserver API | ||
|
||
A code example: | ||
{[ | ||
if (PerformanceObserver.is_supported()) then | ||
let entry_types = [ "measure" ] in | ||
let f entries observer = | ||
let entries = entries##getEntries in | ||
Firebug.console##debug entries ; | ||
Firebug.console##debug observer | ||
in | ||
PerformanceObserver.observe ~entry_types ~f | ||
() | ||
]} | ||
|
||
@see <https://developer.mozilla.org/en-US/docs/Web/API/PerformanceObserver> for API documentation. | ||
*) | ||
|
||
class type performanceObserverInit = | ||
object | ||
method entryTypes : Js.js_string Js.t Js.js_array Js.t Js.writeonly_prop | ||
end | ||
|
||
class type performanceEntry = | ||
object | ||
method name : Js.js_string Js.t Js.readonly_prop | ||
|
||
method entryType : Js.js_string Js.t Js.readonly_prop | ||
|
||
method startTime : float Js.readonly_prop | ||
|
||
method duration : float Js.readonly_prop | ||
end | ||
|
||
class type performanceObserverEntryList = | ||
object | ||
method getEntries : performanceEntry Js.t Js.js_array Js.t Js.meth | ||
end | ||
|
||
class type performanceObserver = | ||
object | ||
method observe : performanceObserverInit Js.t -> unit Js.meth | ||
|
||
method disconnect : unit Js.meth | ||
|
||
method takeRecords : performanceEntry Js.t Js.js_array Js.t Js.meth | ||
end | ||
|
||
val performanceObserver : | ||
( (performanceObserverEntryList Js.t -> performanceObserver Js.t -> unit) Js.callback | ||
-> performanceObserver Js.t) | ||
Js.constr | ||
|
||
val is_supported : unit -> bool | ||
|
||
val observe : | ||
entry_types:string list | ||
-> f:(performanceObserverEntryList Js.t -> performanceObserver Js.t -> unit) | ||
-> performanceObserver Js.t |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
i wonder if
is_supported
should be baked in, or left to user space? genuine ask, not a passive challenge :)Uh oh!
There was an error while loading. Please reload this page.
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.
What do you mean by baked in ?
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.
sorry, it's a quirky phrase :)
one may observe that https://developer.mozilla.org/en-US/docs/Web/API/PerformanceObserver/isSupported doesn't exist. thus, i am asking "should jsoo decorate web apis with extra functions, methods, or properties?"
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.
I've included
is_supported
for consistency with the existingintersectionObserver
andresizeObserver
APIs. One could quite reasonably argue that jsoo should just expose web APIs and nothing more, and I might even agree with it. However, I think this PR does the correct thing by following the existing convention.