Created
September 15, 2024 13:33
-
-
Save anotherjesse/b28b9592f1840f722afcce919ba49d47 to your computer and use it in GitHub Desktop.
list gems recipe
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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