Socket
Book a DemoInstallSign in
Socket

@thebrubaker/sync-store

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@thebrubaker/sync-store

Core functionality for the Dough multiplayer state system

latest
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

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';

// 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

Keywords

state

FAQs

Package last updated on 18 Apr 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts