File tree Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -308,7 +308,8 @@ export class Model<N extends JsonNode = JsonNode<any>> implements Printable {
308
308
309
309
/**
310
310
* Applies a single patch to the document. All mutations to the model must go
311
- * through this method.
311
+ * through this method. (With the only exception of local changes through API,
312
+ * which have an alternative path.)
312
313
*/
313
314
public applyPatch ( patch : Patch ) {
314
315
this . onbeforepatch ?.( patch ) ;
@@ -492,7 +493,11 @@ export class Model<N extends JsonNode = JsonNode<any>> implements Printable {
492
493
decoder . decode ( blob , < any > this ) ;
493
494
this . clock = to . clock . clone ( ) ;
494
495
this . ext = to . ext . clone ( ) ;
495
- this . _api ?. flush ( ) ;
496
+ const api = this . _api ;
497
+ if ( api ) {
498
+ api . flush ( ) ;
499
+ api . builder . clock = this . clock ;
500
+ }
496
501
index . forEach ( ( { v : node } ) => {
497
502
const api = node . api as NodeApi | undefined ;
498
503
if ( ! api ) return ;
Original file line number Diff line number Diff line change @@ -252,4 +252,19 @@ describe('reset()', () => {
252
252
doc1 . reset ( doc2 ) ;
253
253
expect ( str . view ( ) ) . toBe ( 'hello' ) ;
254
254
} ) ;
255
+
256
+ test ( 'uses the same clock in Model and NodeBuilder' , async ( ) => {
257
+ const doc1 = Model . create ( ) . setSchema (
258
+ schema . obj ( {
259
+ text : schema . str ( 'hell' ) ,
260
+ } ) ,
261
+ ) ;
262
+ const doc2 = doc1 . fork ( ) ;
263
+ doc2 . s . text . toApi ( ) . ins ( 4 , 'o' ) ;
264
+ expect ( doc1 . clock ) . toBe ( doc1 . api . builder . clock ) ;
265
+ expect ( doc2 . clock ) . toBe ( doc2 . api . builder . clock ) ;
266
+ doc1 . reset ( doc2 ) ;
267
+ expect ( doc1 . clock ) . toBe ( doc1 . api . builder . clock ) ;
268
+ expect ( doc2 . clock ) . toBe ( doc2 . api . builder . clock ) ;
269
+ } ) ;
255
270
} ) ;
You can’t perform that action at this time.
0 commit comments