Skip to content

garethpaul/poe-games-procedural-dungeons / .claude/skills/synced-store

synced-store

Verified

Build apps that USE synced-store for real-time multiplayer state. PROACTIVELY load when: designing a new Poe tile's state/schema (even before any file exists), discussing how to hide, gate, or restrict visibility of data to specific users or to the server, writing schema.ts/mutators/*.ts/client-config.ts/backend-config.ts for a Poe tile, using createPoeTileTestHarness, calling store.subscribe/store.mutate, or wiring entry.tsx with setupStore.

references/ui-patterns.md

View on GitHub
<!-- owner: jyoung-q -->
# Synced-Store UI Subscription Patterns

## Table of Contents
- [React / Preact](#react--preact)
- [SolidJS](#solidjs)
- [System Tables](#system-tables)
- [Store Client API](#store-client-api)

## React / Preact

```typescript
import { useState, useEffect } from "react"; // or "preact/hooks"
import type { TileStoreClient, ItemType } from "../client";

export function App({ store }: { store: TileStoreClient }) {
  const [items, setItems] = useState<ItemType[]>([]);

  useEffect(() => {
    const unsubscribe = store.subscribe(
      (tx) => tx.table("items").entries().toArray(),
      (entries) => {
        setItems(entries.map(([, v]) => v as ItemType).sort((a, b) => a.order - b.order));
      },
    );
    return unsubscribe;
  }, [store]);

  // Mutate — fire-and-forget (optimistic)
  const addItem = () => {
    store.mutate.setItem({ id: crypto.randomUUID(), text: "new" });
  };

  return <ul>{items.map(i => <li key={i.id}>{i.text}</li>)}</ul>;
}
```

**Provider pattern** (React): Create a context + hook so components don't receive `store` as a prop:
```typescript
const StoreContext = createContext<TileStoreClient | null>(null);
export const useStore = () => useContext(StoreContext)!;
// Wrap in entry.tsx: <StoreContext.Provider value={store}><App /></StoreContext.Provider>
```

## SolidJS

```typescript
import { createStore, reconcile } from "solid-js/store";
import { onMount, onCleanup, For } from "solid-js";

export function App(props: { store: TileStoreClient }) {
  const [state, setState] = createStore<{ items: ItemType[] }>({ items: [] });

  onMount(() => {
    const unsub = props.store.subscribeToTable("items", (entries) => {
      const items = (entries as [{ itemKey: string }, ItemType][])
        .map(([, v]) => v)
        .sort((a, b) => a.order - b.order);
      setState("items", reconcile(items, { key: "id" }));
    });
    onCleanup(() => unsub());
  });

  return <For each={state.items}>{(item) => <div>{item.text}</div>}</For>;
}
```

**Key difference**: SolidJS uses `subscribeToTable(name, callback)` instead of `subscribe(query, callback)`. Use `reconcile()` with a key to preserve DOM nodes across updates (see `docs/solidjs-best-practices.md`).

## System Tables

For member profiles, membership roster, current-user lookup in the UI, and permission checks, see [getting-user-info-of-members.md](getting-user-info-of-members.md) — covers `$userInfo`, `$users`, `$permissions`, and the `getUserInfo` helper.

## Store Client API

```typescript
// Mutations (optimistic, returns confirmation promise)
const { confirmed } = await store.mutate.myMutator(input);
await confirmed; // wait for server acknowledgement

// Queries
const value = await store.query((tx) => tx.table("items").get("key"));

// Subscriptions (React)
const unsub = store.subscribe(
  (tx) => tx.table("items").entries().toArray(),
  (result) => { /* called on every change */ },
);
unsub(); // cleanup

// Subscriptions (SolidJS)
const unsub = store.subscribeToTable("items", (entries, changes) => {
  // entries: full snapshot
  // changes: { added: string[], modified: string[], removed: string[] }
});
```
brainstormingobra/superpowersYou MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).Stars: 322kUpdated Claude CodeCodexVerifiedInstall
brand-guidelinesanthropics/skillsApplies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
frontend-designanthropics/skillsGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
mcp-builderanthropics/skillsGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).Stars: 198kUpdated Claude CodeCodexVerifiedInstall