From 20dee180b8b25f45605c637371e289ca68a5a49d Mon Sep 17 00:00:00 2001 From: nojaf Date: Wed, 20 Nov 2024 09:54:17 +0100 Subject: [PATCH 1/2] Improve fetch binding --- src/DOMAPI/Window.js | 4 ++-- src/DOMAPI/Window.res | 21 +++++++++++++++++++-- src/Global.res | 23 +++++++++++++++++++++-- tests/Global__test.js | 9 +++++++++ tests/Global__test.res | 3 +++ 5 files changed, 54 insertions(+), 6 deletions(-) create mode 100644 tests/Global__test.js create mode 100644 tests/Global__test.res diff --git a/src/DOMAPI/Window.js b/src/DOMAPI/Window.js index 977be07..dbf8d92 100644 --- a/src/DOMAPI/Window.js +++ b/src/DOMAPI/Window.js @@ -1,7 +1,7 @@ // Generated by ReScript, PLEASE EDIT WITH CARE -import * as EventTarget$WebApi from "../EventAPI/EventTarget.js"; +import * as EventTarget$WebAPI from "../EventAPI/EventTarget.js"; -EventTarget$WebApi.Impl({}); +EventTarget$WebAPI.Impl({}); /* Not a pure module */ diff --git a/src/DOMAPI/Window.res b/src/DOMAPI/Window.res index ce403a2..fdca408 100644 --- a/src/DOMAPI/Window.res +++ b/src/DOMAPI/Window.res @@ -294,16 +294,33 @@ external structuredClone: (window, 't, ~options: structuredSerializeOptions=?) = "structuredClone" /** +`fetch(window, string, init)` + +Starts the process of fetching a resource from the network, +returning a promise that is fulfilled once the response is available. + +```res +let response = await window->Window.fetch("https://rescript-lang.org") +``` + [Read more on MDN](https://developer.mozilla.org/docs/Web/API/Window/fetch) */ @send -external fetch: (window, ~input: request, ~init: requestInit=?) => Promise.t = "fetch" +external fetch: (window, string, ~init: requestInit=?) => Promise.t = "fetch" /** +`fetch_withRequest(window, request, init)` + +Starts the process of fetching a resource from the network, +returning a promise that is fulfilled once the response is available. + +```res +let response = await window->Window.fetch(myRequest) +``` [Read more on MDN](https://developer.mozilla.org/docs/Web/API/Window/fetch) */ @send -external fetch2: (window, ~input: string, ~init: requestInit=?) => Promise.t = "fetch" +external fetch_withRequest: (window, request, ~init: requestInit=?) => Promise.t = "fetch" /** [Read more on MDN](https://developer.mozilla.org/docs/Web/API/DedicatedWorkerGlobalScope/requestAnimationFrame) diff --git a/src/Global.res b/src/Global.res index f1932ae..a5b6e66 100644 --- a/src/Global.res +++ b/src/Global.res @@ -480,14 +480,33 @@ external createImageBitmap18: ( external structuredClone: ('t, ~options: structuredSerializeOptions=?) => 't = "structuredClone" /** +`fetch(string, init)` + +Starts the process of fetching a resource from the network, +returning a promise that is fulfilled once the response is available. + +```res +let response = await fetch("https://rescript-lang.org") +``` + [Read more on MDN](https://developer.mozilla.org/docs/Web/API/Window/fetch) */ -external fetch: (~input: request, ~init: requestInit=?) => Promise.t = "fetch" +external fetch: (string, ~init: requestInit=?) => Promise.t = "fetch" /** +`fetch_withRequest(request, init)` + +Starts the process of fetching a resource from the network, +returning a promise that is fulfilled once the response is available. + +```res +let response = await fetch(myRequest) +``` + [Read more on MDN](https://developer.mozilla.org/docs/Web/API/Window/fetch) */ -external fetch2: (~input: string, ~init: requestInit=?) => Promise.t = "fetch" +@send +external fetch_withRequest: (request, ~init: requestInit=?) => Promise.t = "fetch" /** [Read more on MDN](https://developer.mozilla.org/docs/Web/API/DedicatedWorkerGlobalScope/requestAnimationFrame) diff --git a/tests/Global__test.js b/tests/Global__test.js new file mode 100644 index 0000000..9a955dc --- /dev/null +++ b/tests/Global__test.js @@ -0,0 +1,9 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE + + +let response = await fetch("https://rescript-lang.org/"); + +export { + response, +} +/* response Not a pure module */ diff --git a/tests/Global__test.res b/tests/Global__test.res new file mode 100644 index 0000000..c08ad7c --- /dev/null +++ b/tests/Global__test.res @@ -0,0 +1,3 @@ +open WebAPI.Global + +let response = await fetch("https://rescript-lang.org/") \ No newline at end of file From fb6427a565eb78e855f66cf4eb497be123757e84 Mon Sep 17 00:00:00 2001 From: nojaf Date: Wed, 20 Nov 2024 09:55:06 +0100 Subject: [PATCH 2/2] Format test --- tests/Global__test.res | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Global__test.res b/tests/Global__test.res index c08ad7c..ff4525e 100644 --- a/tests/Global__test.res +++ b/tests/Global__test.res @@ -1,3 +1,3 @@ open WebAPI.Global -let response = await fetch("https://rescript-lang.org/") \ No newline at end of file +let response = await fetch("https://rescript-lang.org/")