@automerge/automerge-repo-react-hooks 2.5.2-alpha.2 → 2.5.2-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -6241,6 +6241,13 @@ const REUSE_BUFFER_MODE = 512;
6241
6241
  const RESET_BUFFER_MODE = 1024;
6242
6242
  const THROW_ON_ITERABLE = 2048;
6243
6243
 
6244
+ /**
6245
+ * FinalizationRegistry for automatic cleanup of Ref instances.
6246
+ * This ensures subscriptions are cleaned up when Refs are garbage collected,
6247
+ * even if dispose() is never called.
6248
+ */
6249
+ new FinalizationRegistry(cleanup => cleanup());
6250
+
6244
6251
  var sha256$1 = {exports: {}};
6245
6252
 
6246
6253
  var sha256 = sha256$1.exports;
@@ -6751,7 +6758,7 @@ class PeerStateView {
6751
6758
  getLastSeenPeer(peers) {
6752
6759
  let freshestLastSeenAt;
6753
6760
  return peers.reduce((freshest, curr) => {
6754
- const lastSeenAt = this.value[curr]?.lastActiveAt;
6761
+ const lastSeenAt = this.value[curr]?.lastSeenAt;
6755
6762
  if (!lastSeenAt) {
6756
6763
  return freshest;
6757
6764
  }
@@ -6845,7 +6852,8 @@ class PeerPresenceInfo {
6845
6852
  ...this.#peerStates.value,
6846
6853
  [peerId]: {
6847
6854
  ...this.#peerStates.value[peerId],
6848
- lastSeen: Date.now(),
6855
+ peerId,
6856
+ lastSeenAt: Date.now(),
6849
6857
  },
6850
6858
  });
6851
6859
  }
@@ -6867,7 +6875,7 @@ class PeerPresenceInfo {
6867
6875
  deviceId,
6868
6876
  userId,
6869
6877
  lastActiveAt: now,
6870
- lastUpdateAt: now,
6878
+ lastSeenAt: now,
6871
6879
  value: {
6872
6880
  ...existingState,
6873
6881
  ...value,
@@ -6891,8 +6899,8 @@ class PeerPresenceInfo {
6891
6899
  */
6892
6900
  prune() {
6893
6901
  const threshold = Date.now() - this.ttl;
6894
- this.#peerStates = new PeerStateView(Object.fromEntries(Object.entries(this.#peerStates).filter(([, state]) => {
6895
- return state.lastActiveAt >= threshold;
6902
+ this.#peerStates = new PeerStateView(Object.fromEntries(Object.entries(this.#peerStates.value).filter(([, state]) => {
6903
+ return state.lastSeenAt >= threshold;
6896
6904
  })));
6897
6905
  }
6898
6906
  /**
@@ -7177,12 +7185,18 @@ function usePresence({
7177
7185
  presence.stop();
7178
7186
  };
7179
7187
  }, [presence, userId, deviceId, firstInitialState, firstOpts]);
7180
- const start = useCallback(() => {
7181
- presence.start({
7182
- initialState: presence.getLocalState(),
7183
- ...firstOpts.current
7184
- });
7185
- }, [presence, firstOpts]);
7188
+ const start = useCallback(
7189
+ (config) => {
7190
+ const initialState2 = config?.initialState ?? presence.getLocalState();
7191
+ const opts = {
7192
+ ...firstOpts.current,
7193
+ ...config,
7194
+ initialState: initialState2
7195
+ };
7196
+ presence.start(opts);
7197
+ },
7198
+ [presence, firstOpts]
7199
+ );
7186
7200
  const stop = useCallback(() => {
7187
7201
  presence.stop();
7188
7202
  }, [presence]);