File tree Expand file tree Collapse file tree 2 files changed +10
-7
lines changed
json-crdt-extensions/peritext/util/__tests__ Expand file tree Collapse file tree 2 files changed +10
-7
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import {Model} from '../../../../json-crdt/model';
33import { ChunkSlice } from '../ChunkSlice' ;
44
55const setup = ( ) => {
6- const model = Model . withLogicalClock ( ) . setSchema ( s . str ( 'Hello world' ) ) ;
6+ const model = Model . withLogicalClock ( ) . setSchema ( s . str ( 'Hello world' ) , false ) ;
77 const node = model . root . node ( ) ;
88 const chunk = node . first ( ) ! ;
99 return {
Original file line number Diff line number Diff line change @@ -403,13 +403,16 @@ export class Model<N extends JsonNode = JsonNode<any>> implements Printable {
403403 * @returns Strictly typed model.
404404 */
405405 public setSchema < S extends NodeBuilder > ( schema : S , useGlobalSession : boolean = true ) : Model < SchemaToJsonNode < S > > {
406- const clock = this . clock ;
407- const sid = useGlobalSession ? SESSION . GLOBAL : clock . sid ;
408- if ( clock . time < 2 ) {
409- const oldSid = clock . sid ;
410- clock . sid = sid ;
406+ const c = this . clock ;
407+ const isNewDocument = c . time === 1 ;
408+ if ( isNewDocument ) {
409+ const oldSid = c . sid ;
410+ if ( useGlobalSession ) c . sid = SESSION . GLOBAL ;
411411 this . api . root ( schema ) ;
412- clock . sid = oldSid ;
412+ if ( useGlobalSession ) {
413+ c . sid = oldSid ;
414+ c . observe ( new clock . Timestamp ( SESSION . GLOBAL , c . time - 1 ) , 1 ) ;
415+ }
413416 }
414417 return < any > this ;
415418 }
You can’t perform that action at this time.
0 commit comments