Skip to content

feat: remote value#2795

Merged
idoros merged 6 commits intomainfrom
ido/remote-value
Nov 23, 2025
Merged

feat: remote value#2795
idoros merged 6 commits intomainfrom
ido/remote-value

Conversation

@idoros
Copy link
Contributor

@idoros idoros commented Nov 22, 2025

This PR adds RemoteValue for cross environment state sharing with auto synchronization on disconnect -> reconnect.

The motivation for this API is that the current event emitter subscribe/unsubscribe pattern does not maintain state/version and therefore cannot automatically re-synchronize after a reconnection. While it is not intended as a replacement for all event-emitter use cases (e.g., streaming logs or other events that have no remote state), it provides a simple and transparent way to handle most stateful cross-environment connections. RemoteValue preserves state and re-establishes synchronization automatically.

Key Features

  • Subscribe/unsubscribe pattern for value changes
  • Version tracking to detect stale values
  • Auto-reconnect and sync on environment reconnection
  • stream() method for immediate value + subscription
  • getValue() for one-time value retrieval

Technical Details

  • Communication layer treats RemoteValue methods specially via dot-notation (counter.subscribe, counter.reconnect, etc.)
  • Version tracking on both sides: subscribers track their current version, reconnection syncs if mismatch detected
  • On environment reconnection, all RemoteValue subscriptions automatically call reconnect() with their current version
  • Only notifies subscribers when value actually changes (identity comparison)
  • Reconnect returns {value, version} if out-of-sync, or null if versions match

@idoros idoros requested a review from barak007 November 22, 2025 09:44
@idoros idoros self-assigned this Nov 22, 2025
@idoros idoros merged commit c18c407 into main Nov 23, 2025
6 checks passed
@idoros idoros deleted the ido/remote-value branch November 23, 2025 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants