Skip to content

Samples #22

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ export default defineConfig({
{
slug: "design-philosophy",
},
{
label: "Examples",
link: "examples",
},
{
slug: "project-status",
},
Expand Down
56 changes: 56 additions & 0 deletions docs/pages/examples.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
import StarlightPage from "@astrojs/starlight/components/StarlightPage.astro";
import { Tabs, TabItem, Code } from "@astrojs/starlight/components";
import { testFiles } from "../utils";

const frontmatter = {
title: "Examples",
};

const headings = testFiles.map(({ name }) => ({
depth: 2,
slug: name,
text: name,
}));
---

<StarlightPage frontmatter={frontmatter} headings={headings}>
<p>
The best example of usage of these bindings are the <a href="./06-testing"
>tests</a
>. <br />
These typically contain tweaks made to the generated bindings to make them more
ergonomic.
</p>
{
testFiles.map(({ source, output, name }) => {
return (
<div class="example" id={name}>
<h2>{name}</h2>
<Tabs>
<TabItem label="ReScript">
<Code code={source} lang="ReScript" frame="none" />
</TabItem>
<TabItem label="JS Output">
<Code code={output} lang="js" frame="none" />
</TabItem>
</Tabs>
</div>
);
})
}
</StarlightPage>
<style>
.example {
margin-block: 4rem;

&:first-of-type {
margin-top: 4rem;
}

& h2 {
margin-bottom: 1rem;
font-size: var(--sl-text-2xl);
}
}
</style>
34 changes: 32 additions & 2 deletions docs/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as path from "node:path";
import { exec } from "node:child_process";
import { promisify } from "node:util";
import { readdirSync, existsSync } from "fs";
import { readdirSync, existsSync, readFileSync } from "fs";
import { micromark } from "micromark";

const execAsync = promisify(exec);
Expand Down Expand Up @@ -140,4 +140,34 @@ export async function getDoc(absoluteFilePath) {
values,
valueHeadings,
};
}
}

function trimRescriptOutput(output) {
return output
.replace("// Generated by ReScript, PLEASE EDIT WITH CARE", "")
.replace("/* response Not a pure module */", "")
.trim();
}

const testDir = path.resolve(process.cwd(), "tests");
export const testFiles =
readdirSync(testDir, { recursive: true })
.filter(f => f.endsWith(".res"))
.map(tf => {
const sourcePath = path.join(testDir, tf);
const source = readFileSync(sourcePath, "utf-8");
const outputPath = sourcePath.replace(".res", ".js");
const output = readFileSync(outputPath, "utf-8");

const parts = tf.split(path.sep);
const name = parts[parts.length - 1].replace("__tests.res", "");

return {
sourcePath: sourcePath.replace(testDir,""),
source,
output: trimRescriptOutput(output),
outputPath: outputPath.replace(testDir,""),
name,
};
})
.sort((a, b) => a.name.localeCompare(b.name));
7 changes: 7 additions & 0 deletions src/DOMAPI.res
Original file line number Diff line number Diff line change
Expand Up @@ -7131,6 +7131,13 @@ type range = {
commonAncestorContainer: node,
}

/**
[See StaticRange on MDN](https://developer.mozilla.org/docs/Web/API/StaticRange)
*/
type staticRange = {
...abstractRange,
}

type nodeFilter = {}

/**
Expand Down
16 changes: 8 additions & 8 deletions src/EventAPI/EventTarget.res
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ The event listener is appended to target's event listener list and is not append
@send
external addEventListener: (
T.t,
~type_: eventType,
~callback: eventListener<'event>,
eventType,
eventListener<'event>,
~options: addEventListenerOptions=?,
) => unit = "addEventListener"

Expand All @@ -56,8 +56,8 @@ The event listener is appended to target's event listener list and is not append
@send
external addEventListener_useCapture: (
T.t,
~type_: eventType,
~callback: eventListener<'event>,
eventType,
eventListener<'event>,
@as(json`true`) _,
) => unit = "addEventListener"

Expand All @@ -68,8 +68,8 @@ Removes the event listener in target's event listener list with the same type, c
@send
external removeEventListener: (
T.t,
~type_: eventType,
~callback: eventListener<'event>,
eventType,
eventListener<'event>,
~options: eventListenerOptions=?,
) => unit = "removeEventListener"

Expand All @@ -80,8 +80,8 @@ Removes the event listener in target's event listener list with the same type, c
@send
external removeEventListener_useCapture: (
T.t,
~type_: eventType,
~callback: eventListener<'event>,
eventType,
eventListener<'event>,
@as(json`true`) _,
) => unit = "removeEventListener"

Expand Down
16 changes: 8 additions & 8 deletions src/Global.res
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,8 @@ The event listener is appended to target's event listener list and is not append
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/EventTarget/addEventListener)
*/
external addEventListener: (
~type_: eventType,
~callback: eventListener<'event>,
eventType,
eventListener<'event>,
~options: addEventListenerOptions=?,
) => unit = "addEventListener"

Expand All @@ -557,8 +557,8 @@ The event listener is appended to target's event listener list and is not append
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/EventTarget/addEventListener)
*/
external addEventListener_useCapture: (
~type_: eventType,
~callback: eventListener<'event>,
eventType,
eventListener<'event>,
@as(json`true`) _,
) => unit = "addEventListener"

Expand All @@ -567,8 +567,8 @@ Removes the event listener in target's event listener list with the same type, c
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/EventTarget/removeEventListener)
*/
external removeEventListener: (
~type_: string,
~callback: eventListener<'event>,
string,
eventListener<'event>,
~options: eventListenerOptions=?,
) => unit = "removeEventListener"

Expand All @@ -577,8 +577,8 @@ Removes the event listener in target's event listener list with the same type, c
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/EventTarget/removeEventListener)
*/
external removeEventListener_useCapture: (
~type_: eventType,
~callback: eventListener<'event>,
eventType,
eventListener<'event>,
@as(json`true`) _,
) => unit = "removeEventListener"

Expand Down
2 changes: 2 additions & 0 deletions src/UIEventsAPI.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading