Skip to content

Instantly share code, notes, and snippets.

@anotherjesse
Created September 15, 2024 13:33
Show Gist options
  • Save anotherjesse/b28b9592f1840f722afcce919ba49d47 to your computer and use it in GitHub Desktop.
Save anotherjesse/b28b9592f1840f722afcce919ba49d47 to your computer and use it in GitHub Desktop.
list gems recipe
import { recipe, lift, UI, NAME, ID, handler } from "@commontools/common-builder";
import { dataGems } from "../data.js";
import { html } from "@commontools/common-html";
const getGems = lift(({ count }) => dataGems.get());
const inc = handler<{}, { count: number }>((_, state) => {
state.count += 1;
});
export const listGems = recipe<{ count: number }>("list gems", ({ count }) => {
count.setDefault(0);
const gems = getGems({ count });
return {
[UI]: html`
<div>
<h2>Current Gems</h2>
<ul>
${gems.map(
(gem) =>
html`<li>
ID: ${gem[ID]}, Name: ${gem[NAME] || "N/A"}
</li>`
)}
</ul>
<common-button onclick=${inc({ count })}>refresh</common-button>
</div>
`,
[NAME]: "List of Current Gems",
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment