Sync Store
Core functionality for a multiplayer state system built on valtio.
Installation
npm install @thebrubaker/sync-store
Usage
import { createStore } from '@thebrubaker/sync-store';
const store = createStore({
count: 0,
todos: []
});
store.state.count += 1;
store.state.todos.push({ id: 'todo_123', text: 'Learn sync-store', completed: false });
const unsubscribe = store.subscribe((operation) => {
console.log('Operation:', operation);
});
store.apply([
{
id: 'op_123',
type: 'SET',
path: ['count'],
value: 5,
timestamp: Date.now(),
actor: 'server'
}
]);
const snapshot = store.takeSnapshot();
store.hydrateFromSnapshot(snapshot);
Features
- Real-time state synchronization
- Conflict resolution
- Operation-based CRDTs
- TypeScript support
- Built on valtio for reactivity
License
MIT