Skip to content

Instantly share code, notes, and snippets.

@anotherjesse
Created September 15, 2024 17:48
Show Gist options
  • Select an option

  • Save anotherjesse/1755064956c171a3a3b55f081d430e1f to your computer and use it in GitHub Desktop.

Select an option

Save anotherjesse/1755064956c171a3a3b55f081d430e1f to your computer and use it in GitHub Desktop.
broken inspect link? gem isn't a cell?
import { recipe, lift, UI, NAME, ID, handler } from "@commontools/common-builder";
import { dataGems, Gem, launch } from "../data.js";
import { html } from "@commontools/common-html";
import { CellImpl } from "@commontools/common-runner";
const dump = lift(({ object }) => JSON.stringify(object, null, 2));
export const jsonView = recipe<{ object: any; name: string }>(
"json debug",
({ name, object }) => {
return {
[NAME]: name,
[UI]: html`<common-vstack gap="sm"
><b>${name}</b>
<pre>${dump({ object })}</pre>
</common-vstack>`,
};
},
);
const inspect = handler<{}, { name: string; object: any }>((_, { name, object }) => {
launch(jsonView, { name, object });
});
const getGems = lift(({ count }) => dataGems.get() as CellImpl<Gem>[]);
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: CellImpl<Gem>) =>
html`<li>
ID: ${gem[ID]}, Name: ${gem[NAME] || "N/A"}
<i onclick=${inspect({ object: gem, name: gem[NAME] })}>inspect</i>
</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