Socket-store is a lightweight WebSocket-first topic state store for JavaScript/TypeScript that routes incoming messages by topic to typed handlers. Version 0.0.3 ships TypeScript types and supports schema-based usage for type safety. It provides store.send, store.subscribe, store.getState, and connection status tracking. Compared to generic WebSocket wrappers, it offers a structured state management pattern similar to Redux but for real-time topics. Released as an early-stage package (0.x.x) with limited adoption; no breaking changes documented yet.
npm install socket-storeNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows how to create typed handlers, instantiate SocketStore, subscribe, send, get state, and manage subscriptions.
Pass an open/connecting WebSocket instance. Use a library like 'reconnecting-websocket' if auto-reconnect is needed.
Explicitly specify state, payload, and topic (as string literal) for full type safety: createMessageHandler<State, Payload, 'topicName'>(...)
Update to 0.0.3 and follow the schema-based usage documented.
Always use { key: 'topicName', data: yourPayload }. The key must match a registered handler topic.Ensure server sends messages as JSON: e.g., { "key": "chat", "data": { ... } }Provide a schema type that matches the handler topics: new SocketStore<AppSchema>(socket, handlers)
import { SocketStore, createMessageHandler } from 'socket-store'Install 'ws' and assign global.WebSocket = require('ws'); or use a polyfill.