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

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

Merged
fhammerschmidt merged 6 commits intomasterfromexperimental-webapi
Jul 3, 2025
Merged

Conversation

@aspeddro
Copy link
Collaborator

No description provided.

@aspeddroaspeddro self-assigned thisJul 1, 2025
@vercel
Copy link

vercelbot commentedJul 1, 2025
edited
Loading

The latest updates on your projects. Learn more aboutVercel for Git ↗︎

NameStatusPreviewCommentsUpdated (UTC)
rescript-lang.org✅ Ready (Inspect)Visit Preview💬Add feedbackJul 2, 2025 7:38pm

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pagesbot commentedJul 1, 2025
edited
Loading

Deploying rescript-lang-org with  Cloudflare Pages  Cloudflare Pages

Latest commit:9e12478
Status: ✅  Deploy successful!
Preview URL:https://559ff893.rescript-lang.pages.dev
Branch Preview URL:https://experimental-webapi.rescript-lang.pages.dev

View logs

Comment on lines 19 to 34
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
})
Copy link
CollaboratorAuthor

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?

cc@nojaf,@fhammerschmidt,@tsnobip

Copy link
Member

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.

aspeddro reacted with thumbs up emoji
letnewLayout=window.innerWidth <breakingPoint ?Column :Row
setLayout(_=>newLayout)
switchpanelRef.current->Nullable.toOption {
|Some(element)=>
Copy link
CollaboratorAuthor

@aspeddroaspeddroJul 1, 2025
edited
Loading

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

Copy link
Member

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

aspeddro reacted with thumbs up emoji
Option.map(suggestions,elements=>
<div
ref={ReactDOM.Ref.domRef(listboxRef)}
ref={ReactDOM.Ref.domRef((Obj.magic(listboxRef):React.ref<Nullable.t<Dom.element>>))}
Copy link
CollaboratorAuthor

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
Copy link
CollaboratorAuthor

@aspeddroaspeddroJul 2, 2025
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Cast toWebAPI.DOMAPI.htmliFrameElement

@aspeddroaspeddro marked this pull request as ready for reviewJuly 2, 2025 17:10
"name":String(name),
"keywords":Array(keywords),
"version":String(version),
"links":Object(dict{"npm":String(npmHref)}aslinks),
Copy link
CollaboratorAuthor

@aspeddroaspeddroJul 2, 2025
edited
Loading

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))})?

Copy link
Member

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.

aspeddro reacted with hooray emoji
Copy link
CollaboratorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Nice!!

meta
->WebAPI.Element.getAttribute("name")
->Nullable.make
->Nullable.toOption

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.

aspeddro reacted with thumbs up emoji
Copy link
Member

@fhammerschmidtfhammerschmidtJul 2, 2025
edited
Loading

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.

@nojaf

Copy link
CollaboratorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Fixed9e12478

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Copy link
Member

@nojafnojaf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Looks good!

@fhammerschmidtfhammerschmidt merged commit2ed9d29 intomasterJul 3, 2025
4 checks passed
@fhammerschmidtfhammerschmidt deleted the experimental-webapi branchJuly 30, 2025 16:02
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@nojafnojafnojaf approved these changes

@fhammerschmidtfhammerschmidtfhammerschmidt approved these changes

@zthzthAwaiting requested review from zth

@tsnobiptsnobipAwaiting requested review from tsnobip

@cometkimcometkimAwaiting requested review from cometkim

Assignees

@aspeddroaspeddro

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

5 participants

@aspeddro@zth@nojaf@fhammerschmidt

[8]ページ先頭

©2009-2025 Movatter.jp