UNPKG

onedionys-real-time-data-syncing

Version:

One Dionys (Real-Time Data Syncing) - A utility for synchronizing data in real-time between clients and servers, allowing web applications to respond to data changes instantly.

39 lines (31 loc) 819 B
// realTimeDataSyncing.js class RealTimeDataSyncing { constructor() { this.data = {}; this.listeners = new Set(); } // Add a listener for data updates addListener(listener) { this.listeners.add(listener); } // Remove a listener removeListener(listener) { this.listeners.delete(listener); } // Update data and notify listeners updateData(key, value) { this.data[key] = value; this.notifyListeners(); } // Get current data getData() { return this.data; } // Notify all listeners about data updates notifyListeners() { for (const listener of this.listeners) { listener(this.data); } } } module.exports = RealTimeDataSyncing;