-
Notifications
You must be signed in to change notification settings - Fork 161
Fix up File
API
#601
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
Comments
I'm trying to tackle this issue next, but I'm wondering how to represent the I currently have the following code: @js.native
@JSGlobal
abstract class File(bits: js.Array[js.Any], name: String, options: FileOptions) extends Blob {
/** Returns the name of the file. For security reasons, the path is excluded from this property. */
def name: String = js.native
/** The File.lastModified read-only property provides the last modified date of the file as the number of milliseconds
* since the Unix epoch (January 1, 1970 at midnight). Files without a known last modified date return the current
* date.
*/
val lastModified: Int = js.native
/** Returns the media type (MIME) of the file represented by a File object. */
def `type`: String = js.native
/** The File.webkitRelativePath is a read-only property that contains a string which specifies the file's path
* relative to the directory selected by the user in an <input> element with its webkitdirectory attribute set.
*
* @return
* A string containing the path of the file relative to the ancestor directory the user selected.
*/
def webkitRelativePath: String = js.native
} Got any ideas or hints on how I can improve this? |
@js.native
@JSGlobal
abstract class File(bits: js.Array[js.Any], name: String, options: FileOptions) extends Blob {
def this(bits: js.Array[js.Any], name: String) = ??? A dummy constructor might work since type facade provides only type and implementation is "erased". |
Ah, but how would that work when you want to pass on a certain The @js.native
trait FilePropertyBag extends js.Object {
def `type`: String = js.native
def lastModified: Int = js.native
}
object FilePropertyBag {
@inline
def apply(
`type`: js.UndefOr[String] = js.undefined,
lastModified: js.UndefOr[Int] = js.undefined
): FilePropertyBag = {
val result = js.Dynamic.literal()
`type`.foreach(result.`type` = _)
lastModified.foreach(result.lastModified = _)
result.asInstanceOf[FilePropertyBag]
}
} But can we improve on this? |
@zetashift great question! You can model Basically we want a
|
Should they really default to
both options have a default value, can't I reuse that? |
@zetashift Yes, I believe they should :) I think those are the defaults it uses if you pass a value of |
Oh TIL, thank you! |
Particularly the constructor: https://developer.mozilla.org/en-US/docs/Web/API/File/File
Noticed while browsing https://github.com/softwaremill/sttp/blob/master/core/src/main/scalajs/sttp/client3/dom/experimental/File.scala.
The text was updated successfully, but these errors were encountered: