Read the root AGENTS.md first. This file adds store-specific rules.
Global state management: createStore, batch, selectors, computed, middleware, and the persist plugin. All in src/store.ts with tests in src/store.test.ts.
createStore(creator, options?)returns auseStorehook with.getState(),.setState(),.subscribe(),.destroy(),.computed().setStatenotifies listeners only when a value actually changed (Object.isbail-out). Preserve this.- New features are opt-in through the
optionsargument. The barecreateStore(creator)call must keep working unchanged. Backward compatibility is required.
- Use the
node:prefix for any Node built-in (node:fs,node:path,node:os). The persist plugin reads and writes files; keep it Node-compatible. - Subscriptions return an unsubscribe function. Honor it.
batch()defers notifications to a microtask. Do not break batching when adding features.
- Real timers off by default. Use
vi.useFakeTimers()for debounce or persist tests andvi.useRealTimers()inafterEach. - Clean up files the persist tests write.
bun vitest run packages/store