- Notifications
You must be signed in to change notification settings - Fork5
Prototype type safe query selector#63
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
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
julien-deoux commentedApr 18, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Hi. First of all, thanks for your work on those bindings, it is much appreciated! Assigning a value to a conditionally chained field actually hits you with a consth2=document.querySelector("h2");if(h2){h2.style.color="red";} Still very succinct for sure, but a fairer comparison. The current version of @rescript/webapi provides an In any case, I'm not sure this function would fit in this library. I like the idea of having zero-cost bindings available and maybe a utility library on the side. The question then becomes: should @rescript/webapi be the zero-cost bindings library, with something like @rescript/webapi-utils for utilities and a more idomatic API, of instead be the accessible default while @rescript/webapi-raw provides the zero-cost version for those who want it? If we suppose the utility library also wraps all nullables with options, we could dream of something like: openWrappedWebAPIGlobal.document->Document.querySelector("h2")->Option.flatMap(HTMLElement.tryParse)->Option.forEach(h2=> {h2.style.color="red"}) which is still quite verbose but doesn't feel too bad to me. |
Hello, thank you for your recent PRs and sharing your thoughts on this. It also makes wonder if we should not go for a workspace approach with multiple packages. |
Got a remark recently on
That it is pretty far from what you can do in JS:
h2?.style.color = "red".Made me wonder if we should include some ergonomic helpers in this library as well.
Thoughts?