@@ -1149,11 +1149,12 @@ export class Document<T, P extends Indexable = Indexable> {
1149
1149
}
1150
1150
1151
1151
/**
1152
- * `removeAppliedLocalChanges` removes local changes applied to the server.
1152
+ * `removePushedLocalChanges` removes local changes that have been applied to
1153
+ * the server from the local changes.
1153
1154
*
1154
1155
* @param clientSeq - client sequence number to remove local changes before it
1155
1156
*/
1156
- private removeAppliedLocalChanges ( clientSeq : number ) {
1157
+ private removePushedLocalChanges ( clientSeq : number ) {
1157
1158
while ( this . localChanges . length ) {
1158
1159
const change = this . localChanges [ 0 ] ;
1159
1160
if ( change . getID ( ) . getClientSeq ( ) > clientSeq ) {
@@ -1175,6 +1176,7 @@ export class Document<T, P extends Indexable = Indexable> {
1175
1176
public applyChangePack ( pack : ChangePack < P > ) : void {
1176
1177
const hasSnapshot = pack . hasSnapshot ( ) ;
1177
1178
1179
+ // 01. Apply snapshot or changes to the root object.
1178
1180
if ( hasSnapshot ) {
1179
1181
this . applySnapshot (
1180
1182
pack . getCheckpoint ( ) . getServerSeq ( ) ,
@@ -1184,20 +1186,18 @@ export class Document<T, P extends Indexable = Indexable> {
1184
1186
) ;
1185
1187
} else if ( pack . hasChanges ( ) ) {
1186
1188
this . applyChanges ( pack . getChanges ( ) , OpSource . Remote ) ;
1189
+ this . removePushedLocalChanges ( pack . getCheckpoint ( ) . getClientSeq ( ) ) ;
1187
1190
}
1188
1191
1189
- // 02. Remove local changes applied to server.
1190
- this . removeAppliedLocalChanges ( pack . getCheckpoint ( ) . getClientSeq ( ) ) ;
1191
-
1192
- // 03. Update the checkpoint.
1192
+ // 02. Update the checkpoint.
1193
1193
this . checkpoint = this . checkpoint . forward ( pack . getCheckpoint ( ) ) ;
1194
1194
1195
- // 04 . Do Garbage collection.
1195
+ // 03 . Do Garbage collection.
1196
1196
if ( ! hasSnapshot ) {
1197
1197
this . garbageCollect ( pack . getVersionVector ( ) ! ) ;
1198
1198
}
1199
1199
1200
- // 05 . Filter detached client's lamport from version vector
1200
+ // 04 . Filter detached client's lamport from version vector
1201
1201
if ( ! hasSnapshot ) {
1202
1202
this . filterVersionVector ( pack . getVersionVector ( ) ! ) ;
1203
1203
}
@@ -1424,7 +1424,7 @@ export class Document<T, P extends Indexable = Indexable> {
1424
1424
// drop clone because it is contaminated.
1425
1425
this . clone = undefined ;
1426
1426
1427
- this . removeAppliedLocalChanges ( clientSeq ) ;
1427
+ this . removePushedLocalChanges ( clientSeq ) ;
1428
1428
1429
1429
// NOTE(hackerwins): If the document has local changes, we need to apply
1430
1430
// them after applying the snapshot, as local changes are not included in the snapshot data.
@@ -1699,6 +1699,7 @@ export class Document<T, P extends Indexable = Indexable> {
1699
1699
if ( event . type === DocEventType . Snapshot ) {
1700
1700
const { snapshot, serverSeq, snapshotVector } = event . value ;
1701
1701
if ( ! snapshot ) return ;
1702
+ // TODO(hackerwins): We need to check the clientSeq of the snapshot.
1702
1703
this . applySnapshot (
1703
1704
BigInt ( serverSeq ) ,
1704
1705
converter . hexToVersionVector ( snapshotVector ) ,
0 commit comments