Pinia

From Esposter/Esposter · View interactive version

Pinia is an AI agent skill from the GitHub repository Esposter/Esposter. Apply when writing or reviewing any Pinia store, or deciding whether logic belongs in a store. Esposter's Pinia stores — how a store is consumed, what state belongs in one and how it is keyed, and how it mutates.

How to use this skill

Skill file

Pinia Store Conventions

Settled — do not re-propose

Consuming a Store

Everywhere a store is consumed, tests included (references/consuming-a-store.md):

Dialog UI State Lives in Per-Service Dialog Stores

Singleton-dialog targets live in a per-service dialog store beside the business store, as strings defaulting to "" (references/dialog-stores.md).

Blade-Scoped Store State — `references/blade-scoped-state.md`

A store is app-lifetime; a ref a component populates for code outside its subtree is not. Whatever a component bridges onto a store in setup, its onUnmounted un-bridges — and on a keyed route the teardown takes the id it owned and is a no-op when the store has moved on. Bridging or tearing one down: that page.

Never Redirect Store Functions — Use Them Directly

A store function is destructured and called where it is used, never forwarded through a composable or wrapper (pass-through-helper/no-forwarding-wrapper); a store cannot be generic, so a generic member is a generic method (references/no-redirects.md).

A shape several stores share is a generic composable called in each store's setup, written once in the headless package that owns the document (useEditSession in vue-block-editor-headless holds the document, history, commit and load the editor stores repeat). The composable forwards no store function, so this rule does not touch it, and no headless package imports Pinia (scripts/src/workspace/packages/headlessPackages.test.ts).

Selection State Belongs in the Store

The selected id is store state with "" as nothing selected, owned by the store's own mutations (references/selection-state.md).

Keyed State — `useDataMap` vs a Plain Map

useDataMap when there is a meaningful current id, a plain ref(new Map()) otherwise; a factory for a class default, every field of per-key state keyed, and a non-overlay write naming its key where it is issued (references/keyed-state-and-pagination.md).

Server Rows Live in the Overlay

tRPC Mutation Placement

A store action that only wraps one $trpc mutate is not written — the caller runs the write itself. A write to a server row is an overlay write with no key; every other mutation takes a required key (references/mutation-actions.md).

Live Updates Reach a Store as Typed Events

A store takes a server change another client made as a typed event, never a tRPC subscription: the feature's use*Subscribables composable registers a handler on useConnectionStore (onRoomEvent, onCallEvent, onUserEvent) that calls the store's store* method (references/cross-surface-state.md).

CRUD Conventions

CRUD verbs over domain verbs, store* for an event-driven counterpart, update in place after a findIndex guard, delete by reassigning (references/crud.md).

Store Action Inputs

An action takes the tRPC input object whole, and only the minimum — the entity comes back in the response (references/action-inputs.md).

Reuse Existing Store Maps — Never Build Local Maps in Actions

Entities another store caches are written through that store's setter — never a transient local Map or a parallel map ref (references/reuse-store-maps.md).

Reactive Map Mutations

Vue 3 tracks Map mutations (set, delete, clear) on a ref(new Map(...)) — mutate in place, no clone and reassign.

Storing Class Instances — `references/class-instances-in-state.md`

Pinia state is deep, so a class instance entering reactive state is recursively proxied — which breaks ECMAScript # field access and devtools traversal. Wrap it in markRaw at the single point it enters (history.value.push(markRaw(command))); read the page before reaching for shallowRef or downgrading # to private instead.

Optimistic Input Clearing on Submit

Clear local form input before await-ing the store action so the field empties instantly, capturing the normalized value in a local variable first so clearing doesn't affect what is passed to the store.

Session Auth in Stores

Never expose sessionId or any raw session identifier as a store state field. A setup store can't await, so it always takes the synchronous form: const session = useSessionData(), accessed as session.value?.user. Both forms and when each applies: the vue skill (references/auth-session.md).

Deep Dives

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.