@@ -124,9 +124,9 @@ internal final class InternalDefaultLiveCounter: Sendable {
124124 action: . known( . counterInc) ,
125125 // RTLC12e3
126126 objectId: mutableState. liveObjectMutableState. objectID,
127- counterOp : . init(
128- // RTLC12e4
129- amount : . init( value: amount) ,
127+ counterInc : . init(
128+ // RTLC12e5
129+ number : . init( value: amount) ,
130130 ) ,
131131 ) ,
132132 )
@@ -223,7 +223,7 @@ internal final class InternalDefaultLiveCounter: Sendable {
223223 }
224224 }
225225
226- /// Merges the initial value from an ObjectOperation into this LiveCounter, per RTLC10 .
226+ /// Merges the initial value from an ObjectOperation into this LiveCounter, per RTLC16 .
227227 internal func nosync_mergeInitialValue( from operation: ObjectOperation ) -> LiveObjectUpdate < DefaultLiveCounterUpdate > {
228228 mutableStateMutex. withoutSync { mutableState in
229229 mutableState. mergeInitialValue ( from: operation)
@@ -238,7 +238,7 @@ internal final class InternalDefaultLiveCounter: Sendable {
238238 }
239239
240240 /// Test-only method to apply a COUNTER_INC operation, per RTLC9.
241- internal func testsOnly_applyCounterIncOperation( _ operation: WireObjectsCounterOp ? ) -> LiveObjectUpdate < DefaultLiveCounterUpdate > {
241+ internal func testsOnly_applyCounterIncOperation( _ operation: WireCounterInc ? ) -> LiveObjectUpdate < DefaultLiveCounterUpdate > {
242242 mutableStateMutex. withSync { mutableState in
243243 mutableState. applyCounterIncOperation ( operation)
244244 }
@@ -352,7 +352,7 @@ internal final class InternalDefaultLiveCounter: Sendable {
352352 // RTLC6c: Set data to the value of ObjectState.counter.count, or to 0 if it does not exist
353353 data = state. counter? . count? . doubleValue ?? 0
354354
355- // RTLC6d: If ObjectState.createOp is present, merge the initial value into the LiveCounter as described in RTLC10
355+ // RTLC6d: If ObjectState.createOp is present, merge the initial value into the LiveCounter as described in RTLC16
356356 // Discard the LiveCounterUpdate object returned by the merge operation
357357 if let createOp = state. createOp {
358358 _ = mergeInitialValue ( from: createOp)
@@ -362,21 +362,25 @@ internal final class InternalDefaultLiveCounter: Sendable {
362362 return ObjectDiffHelpers . calculateCounterDiff ( previousData: previousData, newData: data)
363363 }
364364
365- /// Merges the initial value from an ObjectOperation into this LiveCounter, per RTLC10 .
365+ /// Merges the initial value from an ObjectOperation into this LiveCounter, per RTLC16 .
366366 internal mutating func mergeInitialValue( from operation: ObjectOperation ) -> LiveObjectUpdate < DefaultLiveCounterUpdate > {
367367 let update : LiveObjectUpdate < DefaultLiveCounterUpdate >
368368
369- // RTLC10a: Add ObjectOperation.counter.count to data, if it exists
370- if let operationCount = operation. counter? . count? . doubleValue {
369+ // RTLC16: Resolve counterCreate from either the direct property or the one
370+ // from which counterCreateWithObjectId was derived (RTO12f16)
371+ let counterCreate = operation. counterCreate ?? operation. counterCreateWithObjectId? . derivedFrom
372+
373+ // RTLC16a: Add counterCreate.count to data, if it exists
374+ if let operationCount = counterCreate? . count? . doubleValue {
371375 data += operationCount
372- // RTLC10c
376+ // RTLC16c
373377 update = . update( DefaultLiveCounterUpdate ( amount: operationCount) )
374378 } else {
375- // RTLC10d
379+ // RTLC16d
376380 update = . noop
377381 }
378382
379- // RTLC10b : Set the private flag createOperationIsMerged to true
383+ // RTLC16b : Set the private flag createOperationIsMerged to true
380384 liveObjectMutableState. createOperationIsMerged = true
381385
382386 return update
@@ -425,11 +429,11 @@ internal final class InternalDefaultLiveCounter: Sendable {
425429 // RTLC7d1b
426430 return true
427431 case . known( . counterInc) :
428- // RTLC7d2
429- let update = applyCounterIncOperation ( operation. counterOp )
430- // RTLC7d2a
432+ // RTLC7d5
433+ let update = applyCounterIncOperation ( operation. counterInc )
434+ // RTLC7d5a
431435 liveObjectMutableState. emit ( update, on: userCallbackQueue)
432- // RTLC7d2b
436+ // RTLC7d5b
433437 return true
434438 case . known( . objectDelete) :
435439 let dataBeforeApplyingOperation = data
@@ -469,14 +473,14 @@ internal final class InternalDefaultLiveCounter: Sendable {
469473 }
470474
471475 /// Applies a `COUNTER_INC` operation, per RTLC9.
472- internal mutating func applyCounterIncOperation( _ operation: WireObjectsCounterOp ? ) -> LiveObjectUpdate < DefaultLiveCounterUpdate > {
476+ internal mutating func applyCounterIncOperation( _ operation: WireCounterInc ? ) -> LiveObjectUpdate < DefaultLiveCounterUpdate > {
473477 guard let operation else {
474- // RTL9e
478+ // RTLC9h
475479 return . noop
476480 }
477481
478- // RTLC9b, RTLC9d
479- let amount = operation. amount . doubleValue
482+ // RTLC9f, RTLC9g
483+ let amount = operation. number . doubleValue
480484 data += amount
481485 return . update( DefaultLiveCounterUpdate ( amount: amount) )
482486 }
0 commit comments