@@ -46,9 +46,8 @@ export class File implements Printable {
4646 if ( history ) {
4747 const [ start , patches ] = history ;
4848 if ( start ) {
49- const startModel = decodeModel ( start ) ;
50- log = new PatchLog ( startModel ) ;
51- for ( const patch of patches ) log . push ( decodePatch ( patch ) ) ;
49+ log = new PatchLog ( ( ) => decodeModel ( start ) ) ;
50+ for ( const patch of patches ) log . end . applyPatch ( decodePatch ( patch ) ) ;
5251 }
5352 }
5453 if ( ! log ) throw new Error ( 'NO_HISTORY' ) ;
@@ -57,7 +56,7 @@ export class File implements Printable {
5756 for ( const patch of frontier ) {
5857 const patchDecoded = decodePatch ( patch ) ;
5958 decodedModel . applyPatch ( patchDecoded ) ;
60- log . push ( patchDecoded ) ;
59+ log . end . applyPatch ( patchDecoded ) ;
6160 }
6261 }
6362 const file = new File ( decodedModel , log ) ;
@@ -88,7 +87,7 @@ export class File implements Printable {
8887 const id = patch . getId ( ) ;
8988 if ( ! id ) return ;
9089 this . model . applyPatch ( patch ) ;
91- this . log . push ( patch ) ;
90+ this . log . end . applyPatch ( patch ) ;
9291 }
9392
9493 /**
@@ -100,10 +99,10 @@ export class File implements Printable {
10099 const api = model . api ;
101100 const autoflushUnsubscribe = api . autoFlush ( ) ;
102101 const onPatchUnsubscribe = api . onPatch . listen ( ( patch ) => {
103- log . push ( patch ) ;
102+ log . end . applyPatch ( patch ) ;
104103 } ) ;
105104 const onFlushUnsubscribe = api . onFlush . listen ( ( patch ) => {
106- log . push ( patch ) ;
105+ log . end . applyPatch ( patch ) ;
107106 } ) ;
108107 return ( ) => {
109108 autoflushUnsubscribe ( ) ;
@@ -153,7 +152,7 @@ export class File implements Printable {
153152 const patchFormat = params . history ?? 'binary' ;
154153 switch ( patchFormat ) {
155154 case 'binary' : {
156- history [ 0 ] = this . log . start . toBinary ( ) ;
155+ history [ 0 ] = this . log . start ( ) . toBinary ( ) ;
157156 this . log . patches . forEach ( ( { v} ) => {
158157 history [ 1 ] . push ( v . toBinary ( ) ) ;
159158 } ) ;
@@ -162,7 +161,7 @@ export class File implements Printable {
162161 case 'compact' : {
163162 const encoder = this . options . structuralCompactEncoder ;
164163 if ( ! encoder ) throw new Error ( 'NO_COMPACT_ENCODER' ) ;
165- history [ 0 ] = encoder . encode ( this . log . start ) ;
164+ history [ 0 ] = encoder . encode ( this . log . start ( ) ) ;
166165 const encodeCompact = this . options . patchCompactEncoder ;
167166 if ( ! encodeCompact ) throw new Error ( 'NO_COMPACT_PATCH_ENCODER' ) ;
168167 const list = history [ 1 ] ;
@@ -174,7 +173,7 @@ export class File implements Printable {
174173 case 'verbose' : {
175174 const encoder = this . options . structuralVerboseEncoder ;
176175 if ( ! encoder ) throw new Error ( 'NO_VERBOSE_ENCODER' ) ;
177- history [ 0 ] = encoder . encode ( this . log . start ) ;
176+ history [ 0 ] = encoder . encode ( this . log . start ( ) ) ;
178177 const encodeVerbose = this . options . patchVerboseEncoder ;
179178 if ( ! encodeVerbose ) throw new Error ( 'NO_VERBOSE_PATCH_ENCODER' ) ;
180179 const list = history [ 1 ] ;
0 commit comments