Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexErrant committed Jan 4, 2025
1 parent 973ee01 commit 533c821
Showing 1 changed file with 10 additions and 21 deletions.
31 changes: 10 additions & 21 deletions packages/keyed/dev/entries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,28 +40,20 @@ const randomKey = (record: Record<string, string>): string => {
};

export default function App() {
const [store, setStore] = createStore<{ entries: Record<string, string> }>({
entries: {
[Math.random()]: "bread",
[Math.random()]: "milk",
[Math.random()]: "honey",
[Math.random()]: "chips",
[Math.random()]: "cookie",
},
const [store, setStore] = createStore<Record<string, string>>({
[Math.random()]: "bread",
[Math.random()]: "milk",
[Math.random()]: "honey",
[Math.random()]: "chips",
[Math.random()]: "cookie",
});

const addRandom = () => {
setStore("entries", Math.random().toString(), getRandomFood());
setStore(Math.random().toString(), getRandomFood());
};
const removeRandom = () =>
setStore(
"entries",
produce(p => {
delete p[randomKey(p)];
}),
);
const removeRandom = () => setStore(p => ({ [randomKey(p)]: undefined }));
const clone = () => setStore("entries", p => JSON.parse(JSON.stringify(p)));
const changeRandomValue = () => setStore("entries", p => ({ [randomKey(p)]: getRandomFood() }));
const changeRandomValue = () => setStore(p => ({ [randomKey(p)]: getRandomFood() }));

return (
<>
Expand All @@ -81,10 +73,7 @@ export default function App() {
</div>
<div class="wrapper-h flex-wrap">
<TransitionGroup name="fade">
<Entries
of={store.entries}
fallback={<p class="bg-yellow-500 p-1 transition-all">No items.</p>}
>
<Entries of={store} fallback={<p class="bg-yellow-500 p-1 transition-all">No items.</p>}>
{(key, value, index) => {
createEffect(() => {
console.log("Effect:", key, value());
Expand Down

0 comments on commit 533c821

Please sign in to comment.