You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `addCollection()` method is deprecated. It remains available for backward compatibility, but new applications should use the new constructor pattern. Existing applications are strongly encouraged to migrate.
198
+
:::
199
+
200
+
#### Example 1b. Multiple Collections
201
+
202
+
The new API allows each collection to have its own replication settings:
@@ -701,37 +814,73 @@ On other platforms, Couchbase Lite doesn’t react to OS backgrounding or foregr
701
814
702
815
You can choose to register for document updates during a replication.
703
816
817
+
#### When to Use Document Listeners
818
+
819
+
- Track which specific documents are syncing
820
+
- Detect replication conflicts
821
+
- Handle document-level replication errors
822
+
- Monitor deleted documents during sync
823
+
824
+
#### Document Replication Data Structure
825
+
826
+
```typescript
827
+
interfaceDocumentReplicationRepresentation {
828
+
isPush:boolean; // true = push, false = pull
829
+
documents:ReplicatedDocument[];
830
+
}
831
+
832
+
interfaceReplicatedDocument {
833
+
id:string; // Document ID
834
+
scopeName:string; // Scope name
835
+
collectionName:string; // Collection name
836
+
flags:string[]; // ['DELETED', 'ACCESS_REMOVED']
837
+
error?: { message:string }; // Present if replication failed
838
+
}
839
+
```
840
+
841
+
**Document Flags:**
842
+
-`'DELETED'` - Document was deleted
843
+
-`'ACCESS_REMOVED'` - User lost access to document
844
+
704
845
For example, the code snippet in [Example 15](#example-15-register-a-document-listener) registers a listener to monitor document replication performed by the replicator referenced by the variable `replicator`. It prints the document ID of each document received and sent. Stop the listener as shown in [Example 16](#example-16-stop-document-listener).
// Start the replicator without resetting the checkpoint
869
+
// Start the replicator
724
870
awaitreplicator.start(false);
725
871
```
726
872
727
873
#### Example 16. Stop document listener
728
874
729
-
This code snippet shows how to stop the document listener using the token from the previous example.
730
-
731
875
```typescript
732
-
awaitthis.replicator.removeChangeListener(token);
876
+
// Remove listener using new API
877
+
awaittoken.remove();
733
878
```
734
879
880
+
:::caution Deprecated
881
+
The `replicator.removeChangeListener(token)` method is deprecated. It remains available for backward compatibility, but new applications should use `token.remove()`. Existing applications are strongly encouraged to migrate.
882
+
:::
883
+
735
884
### Document Access Removal Behavior
736
885
737
886
When access to a document is removed on Sync Gateway (see: Sync Gateway’s [Sync Function](https://docs.couchbase.com/sync-gateway/current/sync-function-api.html)), the document replication listener sends a notification with the `AccessRemoved` flag set to `true` and subsequently purges the document from the database.
@@ -763,10 +912,10 @@ You can find further information on database operations in [Databases](../databa
763
912
764
913
```typescript
765
914
// Remove the change listener
766
-
awaitthis.replicator.removeChangeListener(token)
915
+
awaittoken.remove()
767
916
768
917
// Stop the replicator
769
-
awaitthis.replicator.stop()
918
+
awaitreplicator.stop()
770
919
```
771
920
772
921
Here we initiate the stopping of the replication using the `stop()` method. It will stop any active `change listener` once the replication is stopped.
@@ -819,15 +968,20 @@ As always, when there is a problem with replication, logging is your friend. You
0 commit comments