@dabble/patches 0.5.8 → 0.5.9

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.
@@ -48,7 +48,7 @@ declare class Patches {
48
48
  trackDocs(docIds: string[]): Promise<void>;
49
49
  /**
50
50
  * Untracks the given document IDs, removing them from the set of tracked documents and notifying listeners.
51
- * Untracked docs will no longer be kept in sync with the server, even if not open locally.
51
+ * Untracked docs will no longer be kept in sync with the server.
52
52
  * Closes any open docs and removes them from the store.
53
53
  * @param docIds - Array of document IDs to untrack.
54
54
  */
@@ -48,7 +48,7 @@ class Patches {
48
48
  }
49
49
  /**
50
50
  * Untracks the given document IDs, removing them from the set of tracked documents and notifying listeners.
51
- * Untracked docs will no longer be kept in sync with the server, even if not open locally.
51
+ * Untracked docs will no longer be kept in sync with the server.
52
52
  * Closes any open docs and removes them from the store.
53
53
  * @param docIds - Array of document IDs to untrack.
54
54
  */
@@ -118,6 +118,7 @@ declare class PatchesSync {
118
118
  protected _handleConnectionChange(connectionState: ConnectionState): void;
119
119
  protected _handleDocsTracked(docIds: string[]): Promise<void>;
120
120
  protected _handleDocsUntracked(docIds: string[]): Promise<void>;
121
+ protected _handleDocChange(docId: string, _changes: Change[]): Promise<void>;
121
122
  }
122
123
 
123
124
  export { PatchesSync, type PatchesSyncOptions, type PatchesSyncState };
@@ -49,6 +49,7 @@ class PatchesSync {
49
49
  patches.onTrackDocs(this._handleDocsTracked.bind(this));
50
50
  patches.onUntrackDocs(this._handleDocsUntracked.bind(this));
51
51
  patches.onDeleteDoc(this._handleDocDeleted.bind(this));
52
+ patches.onChange(this._handleDocChange.bind(this));
52
53
  }
53
54
  /**
54
55
  * Gets the URL of the WebSocket connection.
@@ -322,6 +323,11 @@ class PatchesSync {
322
323
  }
323
324
  }
324
325
  }
326
+ async _handleDocChange(docId, _changes) {
327
+ if (!this.state.connected) return;
328
+ if (!this.trackedDocs.has(docId)) return;
329
+ await this.flushDoc(docId);
330
+ }
325
331
  }
326
332
  _init = __decoratorStart(null);
327
333
  __decorateElement(_init, 1, "syncDoc", _syncDoc_dec, PatchesSync);
@@ -58,7 +58,7 @@ class DocManager {
58
58
  }
59
59
  if (currentCount === 1) {
60
60
  this.refCounts.delete(docId);
61
- await patches.closeDoc(docId);
61
+ await patches.closeDoc(docId, { untrack: true });
62
62
  } else {
63
63
  this.refCounts.set(docId, currentCount - 1);
64
64
  }
@@ -58,7 +58,7 @@ class DocManager {
58
58
  }
59
59
  if (currentCount === 1) {
60
60
  this.refCounts.delete(docId);
61
- await patches.closeDoc(docId);
61
+ await patches.closeDoc(docId, { untrack: true });
62
62
  } else {
63
63
  this.refCounts.set(docId, currentCount - 1);
64
64
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dabble/patches",
3
- "version": "0.5.8",
3
+ "version": "0.5.9",
4
4
  "description": "Immutable JSON Patch implementation based on RFC 6902 supporting operational transformation and last-writer-wins",
5
5
  "author": "Jacob Wright <jacwright@gmail.com>",
6
6
  "bugs": {