Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Proof of concept querySelector helpers#13

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
nojaf wants to merge3 commits intomain
base:main
Choose a base branch
Loading
fromquery-selector
Draft

Conversation

@nojaf
Copy link
Member

Somewhat related to#5

I'd like to experiment a bit with the same trick that was used in the original webapi bindings:

moduleImpl= (T: {typet  },)=> {

Some duplication in the methods, which currently exists, can be avoided by this.

@zth
Copy link
Member

zth commentedNov 18, 2024

My 5c is that we should avoid reusing that trick. In my view it just makes the code more complicated and hard to follow for little gain.

@nojaf
Copy link
MemberAuthor

There are currently about 60 files that usequerySelector. Adding a safe version for each element type could result in significant duplication.

@zth
Copy link
Member

zth commentedNov 18, 2024

Well, usinginclude creates that same duplication in the compiler anyway (include is a copy paste in the compiler). It's not in theReScript source files, but it'll be the same duplication in the output. And the output will probably be worse and harder to follow.

What about just using functions? Some internal function that takes a classifier or similar for each use case. Then we can just partially apply that same function in all relevant places. If we worry about duplication.

@nojaf
Copy link
MemberAuthor

I don't think I mind duplication, but in this case, there is practical side.
I would add about 60 helpers for type safequerySelector access and would need to add those in 60 files.
Theinclude trick makes this that second part easier. Especially if we revisit bindings.

What about just using functions? Some internal function that takes a classifier or similar for each use case. Then we can just partially apply that same function in all relevant places. If we worry about duplication.

Could you give an example maybe?

@zth
Copy link
Member

zth commentedNov 18, 2024

Just so I understand correctly - you mean each of these 60 files get 60 variations of querySelector? So we have 3600 bindings to queryselector essentially?

@nojaf
Copy link
MemberAuthor

Yeah, so you havedocument.querySelector which returns an element.
In this first example I've added aquerySelector_htmlCanvasElement helper to the document module.
But any HTMLElement interface has thequerySelector method as well, because of theElement inheritance.

The way it is currently set up is thatHTMLButtonElement for example, currently has a@send querySelector taking anhtmlButtonElement as first argument. This is to avoid that the user would need to "downcast" thehtmlButtonElement to anelement before they can usequerySelector.

@nojaf
Copy link
MemberAuthor

@zth I've added an example to illustrate this in374f47c

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@nojaf@zth

[8]ページ先頭

©2009-2025 Movatter.jp