@thebrubaker/sync-store
v1.0.0
Published
Core functionality for the Dough multiplayer state system
Maintainers
Readme
Sync Store
Core functionality for a multiplayer state system built on valtio.
Installation
npm install @thebrubaker/sync-storeUsage
import { createStore } from '@thebrubaker/sync-store';
// Create a store with initial state
const store = createStore({
count: 0,
todos: []
});
// Access the state directly
store.state.count += 1;
store.state.todos.push({ id: 'todo_123', text: 'Learn sync-store', completed: false });
// Subscribe to state changes
const unsubscribe = store.subscribe((operation) => {
console.log('Operation:', operation);
// Send operation to server or other clients
});
// Apply operations from server or other clients
store.apply([
{
id: 'op_123',
type: 'SET',
path: ['count'],
value: 5,
timestamp: Date.now(),
actor: 'server'
}
]);
// Take a snapshot
const snapshot = store.takeSnapshot();
// Hydrate from a snapshot
store.hydrateFromSnapshot(snapshot);Features
- Real-time state synchronization
- Conflict resolution
- Operation-based CRDTs
- TypeScript support
- Built on valtio for reactivity
License
MIT
