@@ -19,23 +19,23 @@ import type {JsonCrdtPatchOperation, Patch} from './Patch';
19
19
*/
20
20
export const combine = ( patches : Patch [ ] ) : void => {
21
21
const firstPatch = patches [ 0 ] ;
22
- let idA = patches [ 0 ] . getId ( ) ;
22
+ const firstPatchId = firstPatch . getId ( ) ;
23
23
const patchesLength = patches . length ;
24
24
for ( let i = 1 ; i < patchesLength ; i ++ ) {
25
25
const currentPatch = patches [ i ] ;
26
- const idB = currentPatch . getId ( ) ;
27
- if ( ! idA ) {
28
- if ( ! idB ) return ;
26
+ const currentPatchId = currentPatch . getId ( ) ;
27
+ if ( ! firstPatchId ) {
28
+ if ( ! currentPatchId ) return ;
29
29
firstPatch . ops = firstPatch . ops . concat ( currentPatch . ops ) ;
30
30
return ;
31
31
}
32
- if ( ! idB ) return ;
33
- if ( ! idA || ! idB ) throw new Error ( 'EMPTY_PATCH' ) ;
34
- const sidA = idA . sid ;
35
- if ( sidA !== idB . sid ) throw new Error ( 'SID_MISMATCH' ) ;
36
- const timeA = idA . time ;
32
+ if ( ! currentPatchId ) return ;
33
+ if ( ! firstPatchId || ! currentPatchId ) throw new Error ( 'EMPTY_PATCH' ) ;
34
+ const sidA = firstPatchId . sid ;
35
+ if ( sidA !== currentPatchId . sid ) throw new Error ( 'SID_MISMATCH' ) ;
36
+ const timeA = firstPatchId . time ;
37
37
const nextTick = timeA + firstPatch . span ( ) ;
38
- const timeB = idB . time ;
38
+ const timeB = currentPatchId . time ;
39
39
const timeDiff = timeB - nextTick ;
40
40
if ( timeDiff < 0 ) throw new Error ( 'TIMESTAMP_CONFLICT' ) ;
41
41
const needsNoop = timeDiff > 0 ;
0 commit comments