-
Notifications
You must be signed in to change notification settings - Fork 161
Migrate beacon to dom #564
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
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package org.scalajs.dom | ||
|
||
import org.scalajs.dom | ||
import scala.scalajs.js | ||
|
||
/** The Beacon interface is used to schedule an asynchronous and non-blocking request to a web server. Beacon requests | ||
* use the HTTP PUT method and requests typically do not require a response. Requests are guaranteed to be initiated | ||
* before a page is unloaded and they are run to completion without requiring a blocking request (for example | ||
* XMLHttpRequest). | ||
* | ||
* @see | ||
* [[https://www.w3.org/TR/2016/WD-beacon-20160204/ Beacon W3C Working Draft]] | ||
* @see | ||
* [[https://developer.mozilla.org/en-US/docs/Web/API/Beacon_API MDN Beacon API]] | ||
*/ | ||
@js.native | ||
trait BeaconNavigator extends js.Object { | ||
|
||
/** The navigator.sendBeacon() method can be used to asynchronously transfer small HTTP data from the User Agent to a | ||
* web server. | ||
* | ||
* @param url | ||
* The url parameter indicates the resolved URL where the data is to be transmitted. | ||
* @param data | ||
* The data parameter is the ArrayBufferView, Blob, DOMString, or FormData data that is to be transmitted. | ||
*/ | ||
def sendBeacon(url: String, data: dom.BodyInit = null): Boolean = js.native | ||
} | ||
|
||
/** The Beacon interface is used to schedule an asynchronous and non-blocking request to a web server. Beacon requests | ||
* use the HTTP PUT method and requests typically do not require a response. Requests are guaranteed to be initiated | ||
* before a page is unloaded and they are run to completion without requiring a blocking request (for example | ||
* XMLHttpRequest). | ||
* | ||
* @see | ||
* [[https://www.w3.org/TR/2016/WD-beacon-20160204/ Beacon W3C Working Draft]] | ||
* @see | ||
* [[https://developer.mozilla.org/en-US/docs/Web/API/Beacon_API MDN Beacon API]] | ||
*/ | ||
@js.native | ||
trait BeaconWorkerNavigator extends js.Object { | ||
|
||
/** The navigator.sendBeacon() method can be used to asynchronously transfer small HTTP data from the User Agent to a | ||
* web server. | ||
* | ||
* @param url | ||
* The url parameter indicates the resolved URL where the data is to be transmitted. | ||
* @param data | ||
* The data parameter is the ArrayBufferView, Blob, DOMString, or FormData data that is to be transmitted. | ||
*/ | ||
def sendBeacon(url: String, data: dom.BodyInit = null): Boolean = js.native | ||
} |
57 changes: 13 additions & 44 deletions
57
src/main/scala/org/scalajs/dom/experimental/beacon/package.scala
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 |
---|---|---|
@@ -1,54 +1,23 @@ | ||
package org.scalajs.dom.experimental | ||
package org.scalajs | ||
package dom | ||
package experimental | ||
|
||
import org.scalajs.dom | ||
import org.scalajs.dom.{Navigator, WorkerNavigator} | ||
import scala.language.implicitConversions | ||
import scala.scalajs.js | ||
|
||
/** The Beacon interface is used to schedule an asynchronous and non-blocking request to a web server. Beacon requests | ||
* use the HTTP PUT method and requests typically do not require a response. Requests are guaranteed to be initiated | ||
* before a page is unloaded and they are run to completion without requiring a blocking request (for example | ||
* XMLHttpRequest). | ||
* | ||
* @see | ||
* [[https://www.w3.org/TR/2016/WD-beacon-20160204/ Beacon W3C Working Draft]] | ||
* @see | ||
* [[https://developer.mozilla.org/en-US/docs/Web/API/Beacon_API MDN Beacon API]] | ||
*/ | ||
package object beacon { | ||
|
||
implicit def toBeaconNavigator(n: Navigator): BeaconNavigator = | ||
n.asInstanceOf[BeaconNavigator] | ||
|
||
implicit def toBeaconWorkerNavigator(n: WorkerNavigator): BeaconWorkerNavigator = { | ||
n.asInstanceOf[BeaconWorkerNavigator] | ||
} | ||
@deprecated("use dom.BeaconNavigator instead", "2.0.0") | ||
type BeaconNavigator = dom.BeaconNavigator | ||
|
||
@js.native | ||
trait BeaconNavigator extends js.Object { | ||
@deprecated("use dom.BeaconWorkerNavigator instead", "2.0.0") | ||
type BeaconWorkerNavigator = dom.BeaconWorkerNavigator | ||
|
||
/** The navigator.sendBeacon() method can be used to asynchronously transfer small HTTP data from the User Agent to | ||
* a web server. | ||
* | ||
* @param url | ||
* The url parameter indicates the resolved URL where the data is to be transmitted. | ||
* @param data | ||
* The data parameter is the ArrayBufferView, Blob, DOMString, or FormData data that is to be transmitted. | ||
*/ | ||
def sendBeacon(url: String, data: dom.BodyInit = null): Boolean = js.native | ||
} | ||
@deprecated("use dom.Navigator.toBeaconNavigator instead", "2.0.0") | ||
implicit def toBeaconNavigator(n: Navigator): BeaconNavigator = | ||
Navigator.toBeaconNavigator(n) | ||
|
||
@js.native | ||
trait BeaconWorkerNavigator extends js.Object { | ||
@deprecated("use dom.WorkerNavigator.toBeaconWorkerNavigator instead", "2.0.0") | ||
implicit def toBeaconWorkerNavigator(n: WorkerNavigator): BeaconWorkerNavigator = | ||
WorkerNavigator.toBeaconWorkerNavigator(n) | ||
|
||
/** The navigator.sendBeacon() method can be used to asynchronously transfer small HTTP data from the User Agent to | ||
* a web server. | ||
* | ||
* @param url | ||
* The url parameter indicates the resolved URL where the data is to be transmitted. | ||
* @param data | ||
* The data parameter is the ArrayBufferView, Blob, DOMString, or FormData data that is to be transmitted. | ||
*/ | ||
def sendBeacon(url: String, data: dom.BodyInit = null): Boolean = js.native | ||
} | ||
} |
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
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.
It would be much simpler and cleaner to directly integrate this method in
Navigator
instead of using those implicit conversions. See for example d7933f9 where I did this for the Vibration API.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.
Good point! I guess the reason they were separated before was to quarantine the experimental methods?
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, that was it. But now it doesn't make sense anymore, and it just obscures the API.