Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork254
Migrate to rescript webapi#1063
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
Uh oh!
There was an error while loading.Please reload this page.
Conversation
vercelbot commentedJul 1, 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.
The latest updates on your projects. Learn more aboutVercel for Git ↗︎
|
cloudflare-workers-and-pagesbot commentedJul 1, 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.
Deploying rescript-lang-org with |
| Latest commit: | 9e12478 |
| Status: | ✅ Deploy successful! |
| Preview URL: | https://559ff893.rescript-lang.pages.dev |
| Branch Preview URL: | https://experimental-webapi.rescript-lang.pages.dev |
| letnodeList=document->WebAPI.Document.querySelectorAll("meta") | ||
| letname=switch (name,property,itemprop) { | ||
| | (Some(name),_,_)=>Some(name) | ||
| | (_,Some(property),_)=>Some(property) | ||
| | (_,_,Some(itemprop))=>Some(itemprop) | ||
| |_=>None | ||
| } | ||
| letnodesArray= [] | ||
| letcontent=meta->Element.getAttribute("content")->Nullable.toOption | ||
| foriin0tonodeList.length { | ||
| letnode=WebAPI.NodeList.item(nodeList,i) | ||
| nodesArray->Array.push(node) | ||
| } | ||
| switch (name,content) { | ||
| | (Some(name),Some(content))=>tags->Dict.set(name,content) | ||
| |_=> () | ||
| } | ||
| letmetaTags=nodesArray->Array.reduce(Dict.fromArray([]), (tags,meta)=> { | ||
| letname=meta->Obj.magic->WebAPI.Element.getAttribute("name") | ||
| tags | ||
| }) | ||
| letcontent=meta->Obj.magic->WebAPI.Element.getAttribute("content") | ||
| tags->Dict.set(name,content) | ||
| tags | ||
| }) |
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.
I'm not sure the best way to do this. In this code I need to access the attribute for each element, however,WebAPI.Document.querySelectorAll returnsWebAPI.DOMAPI.nodelist and not anarray<WebAPI.DOMAPI.element>. There are severalObj.magic
Some suggestion?
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.
You could try thehttps://developer.mozilla.org/en-US/docs/Web/API/NodeList/values
Orhttps://developer.mozilla.org/en-US/docs/Web/API/NodeList/forEach
In JS, you can spread a NodeList into an array like[...document.querySelectorAll(".blah").
But you do have withnode interface. You could doinstanceof Element interopt check, but you will need to cast at some point.
| letnewLayout=window.innerWidth <breakingPoint ?Column :Row | ||
| setLayout(_=>newLayout) | ||
| switchpanelRef.current->Nullable.toOption { | ||
| |Some(element)=> |
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.
Here,element of typeWebAPI.DOMAPI.element dont have thestyle property.
https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style
I could modify the height access theheight property ->element.style.height = "100px", instead of useWebAPI.Element.setAttribute
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.
instanceof HTMLElement and cast tohtmlElement maybe?
This is not ideal and brought forwardrescript-lang/experimental-rescript-webapi#5 andrescript-lang/experimental-rescript-webapi#13
| Option.map(suggestions,elements=> | ||
| <div | ||
| ref={ReactDOM.Ref.domRef(listboxRef)} | ||
| ref={ReactDOM.Ref.domRef((Obj.magic(listboxRef):React.ref<Nullable.t<Dom.element>>))} |
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.
ReactDOM.Ref.domRef exceptReact.ref<Nullable.t<Dom.element>>, but this have typeReact.ref<Nullable.t<WebAPI.DOMAPI.htmlElement>>
| switchelement->Element.contentWindow { | ||
| |Some(win)=>win->Element.postMessageAny({code,imports}, ~targetOrigin="*") | ||
| |None=>Console.error("contentWindow not found") | ||
| letelement:WebAPI.DOMAPI.htmliFrameElement=element->Obj.magic |
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.
Cast toWebAPI.DOMAPI.htmliFrameElement
src/Packages.res Outdated
| "name":String(name), | ||
| "keywords":Array(keywords), | ||
| "version":String(version), | ||
| "links":Object(dict{"npm":String(npmHref)}aslinks), |
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.
Testing new dict pattern matching.@zth I can match optional fields (ex:dict{"npm": String(npmHref), "repository": ?Some(String(repo))})?
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! It's an optional field underlying so you need to specify if you want to match on the optionality.
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.
Nice!!
src/common/MetaTagsApi.res Outdated
| meta | ||
| ->WebAPI.Element.getAttribute("name") | ||
| ->Nullable.make | ||
| ->Nullable.toOption |
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.
I think theNullable.toOption is unnecessary - we can match onValue(name) etc. below instead.
fhammerschmidtJul 2, 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.
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.
Also very weird thatgetAttribute does not returnnullable<string> or evennull<string> as the docs clearly state that that could be the case.
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.
Fixed9e12478
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 inrescript-lang/experimental-rescript-webapi#120 as well
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.
Looks good!
2ed9d29 intomasterUh oh!
There was an error while loading.Please reload this page.

No description provided.