-
Notifications
You must be signed in to change notification settings - Fork 161
Add URL.searchParams (URLSearchParams) #361
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
Conversation
* MDN | ||
*/ | ||
@js.native | ||
trait URLSearchParamsInterface 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.
There doesn't seem to exist an URLSearchParamsInterface
even in the IDL definitions. Consider just defining the class URLSearchParams
.
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.
Fixed in 1db81ff
It was separated as MDN says URLSearchParams has separate "interface" and constructor.
But, same name between trait and class is not allowed in Scala, so it was suffixed with ~Interface
.
By separating trait, we can have our own class that implements URLSearchParams interface.
However, I change my mind to just define class, since URL
is defined so.
} | ||
|
||
/** | ||
* The URLSearchParams() constructor creates and returns a new URLSearchParams object. Leading '?' characters are ignored. |
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.
Please wrap lines at 80 characters.
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.
Removed this line during merging trait and class.
*/ | ||
@js.native | ||
@JSGlobal | ||
class URLSearchParams extends URLSearchParamsInterface { |
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 class should extend js.Iterable[js.Tuple2[String, String]]
.
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.
Fixed
def entries(): js.Iterator[js.Tuple2[String, String]] = js.native | ||
|
||
@JSName(js.Symbol.iterator) | ||
def values(): js.Iterator[String] = 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.
Those two methods with different signatures and the same @JSName
make no sense. I think what you wanted is a single def iterator(): js.Iterator[js.Tuple2[String, String]]
to conform to the interface of js.Iterable[js.Tuple2[String, String]]
. The methods entries()
and values()
should not have any @JSName
. It also seems that you're missing the def keys()
method.
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.
Correct.
Implemented js.Iterable[js.Tuple2[String, String]]
and used @JSName
to override def jsIterator
.
keys
also added.
1db81ff
to
e650ea9
Compare
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.
An unrelated change made it into the PR, which should not be there. Otherwise good to go.
@@ -276,7 +276,7 @@ object Ajax { | |||
} else { | |||
// fall back to copying the data | |||
val tempBuffer = ByteBuffer.allocateDirect(data.remaining) | |||
val origPosition = data.position | |||
val origPosition = data.position() |
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.
This change is unrelated and should not be in this commit/PR.
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.
Ah, indeed.
Since it was fixed in another PR, I will rebase and exclude unrelated change.
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.
Removed !!
Closes #339
URLSearchParams is widely-adopted standard.