@@ -4,18 +4,20 @@ import { ObjectMessage, ObjectOperation, ObjectOperationAction, ObjectsCounterOp
44import { Objects } from './objects' ;
55
66export interface LiveCounterData extends LiveObjectData {
7- data : number ;
7+ data : number ; // RTLC3
88}
99
1010export interface LiveCounterUpdate extends LiveObjectUpdate {
1111 update : { amount : number } ;
1212}
1313
14+ /** @spec RTLC1, RTLC2 */
1415export class LiveCounter extends LiveObject < LiveCounterData , LiveCounterUpdate > {
1516 /**
1617 * Returns a {@link LiveCounter} instance with a 0 value.
1718 *
1819 * @internal
20+ * @spec RTLC4
1921 */
2022 static zeroValue ( objects : Objects , objectId : string ) : LiveCounter {
2123 return new LiveCounter ( objects , objectId ) ;
@@ -122,9 +124,10 @@ export class LiveCounter extends LiveObject<LiveCounterData, LiveCounterUpdate>
122124 } ;
123125 }
124126
127+ /** @spec RTLC5 */
125128 value ( ) : number {
126- this . _objects . throwIfInvalidAccessApiConfiguration ( ) ;
127- return this . _dataRef . data ;
129+ this . _objects . throwIfInvalidAccessApiConfiguration ( ) ; // RTLC5a, RTLC5b
130+ return this . _dataRef . data ; // RTLC5c
128131 }
129132
130133 /**
@@ -221,6 +224,7 @@ export class LiveCounter extends LiveObject<LiveCounterData, LiveCounterUpdate>
221224
222225 /**
223226 * @internal
227+ * @spec RTLC6
224228 */
225229 overrideWithObjectState ( objectState : ObjectState ) : LiveCounterUpdate | LiveObjectUpdateNoop {
226230 if ( objectState . objectId !== this . getObjectId ( ) ) {
@@ -252,7 +256,7 @@ export class LiveCounter extends LiveObject<LiveCounterData, LiveCounterUpdate>
252256
253257 // object's site serials are still updated even if it is tombstoned, so always use the site serials received from the operation.
254258 // should default to empty map if site serials do not exist on the object state, so that any future operation may be applied to this object.
255- this . _siteTimeserials = objectState . siteTimeserials ?? { } ;
259+ this . _siteTimeserials = objectState . siteTimeserials ?? { } ; // RTLC6a
256260
257261 if ( this . isTombstoned ( ) ) {
258262 // this object is tombstoned. this is a terminal state which can't be overridden. skip the rest of object state message processing
@@ -265,8 +269,9 @@ export class LiveCounter extends LiveObject<LiveCounterData, LiveCounterUpdate>
265269 this . tombstone ( ) ;
266270 } else {
267271 // override data for this object with data from the object state
268- this . _createOperationIsMerged = false ;
269- this . _dataRef = { data : objectState . counter ?. count ?? 0 } ;
272+ this . _createOperationIsMerged = false ; // RTLC6b
273+ this . _dataRef = { data : objectState . counter ?. count ?? 0 } ; // RTLC6c
274+ // RTLC6d
270275 if ( ! this . _client . Utils . isNil ( objectState . createOp ) ) {
271276 this . _mergeInitialDataFromCreateOperation ( objectState . createOp ) ;
272277 }
@@ -285,6 +290,7 @@ export class LiveCounter extends LiveObject<LiveCounterData, LiveCounterUpdate>
285290 return ;
286291 }
287292
293+ /** @spec RTLC4 */
288294 protected _getZeroValueData ( ) : LiveCounterData {
289295 return { data : 0 } ;
290296 }
@@ -299,8 +305,8 @@ export class LiveCounter extends LiveObject<LiveCounterData, LiveCounterUpdate>
299305 // note that it is intentional to SUM the incoming count from the create op.
300306 // if we got here, it means that current counter instance is missing the initial value in its data reference,
301307 // which we're going to add now.
302- this . _dataRef . data += objectOperation . counter ?. count ?? 0 ;
303- this . _createOperationIsMerged = true ;
308+ this . _dataRef . data += objectOperation . counter ?. count ?? 0 ; // RTLC6d1
309+ this . _createOperationIsMerged = true ; // RTLC6d2
304310
305311 return { update : { amount : objectOperation . counter ?. count ?? 0 } } ;
306312 }
0 commit comments