File tree Expand file tree Collapse file tree 2 files changed +12
-1
lines changed
src/persisters/persister-automerge Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import {
1010 objGet ,
1111 objHas ,
1212 objIsEmpty ,
13+ objNew ,
1314 objSize ,
1415 objToArray ,
1516} from '../../common/obj.ts' ;
@@ -135,7 +136,7 @@ export const createAutomergePersister = ((
135136 docObjName = TINYBASE ,
136137 onIgnoredError ?: ( error : any ) => void ,
137138) : AutomergePersister => {
138- docHandle . change ( ( doc : any ) => ( doc [ docObjName ] = { } ) ) ;
139+ docHandle . change ( ( doc : any ) => objEnsure ( doc , docObjName , objNew ) ) ;
139140
140141 const getPersisted = async ( ) : Promise < Content | undefined > => {
141142 const doc = await docHandle . doc ( ) ;
Original file line number Diff line number Diff line change @@ -101,6 +101,16 @@ describe('Load from doc', () => {
101101 await persister1 . load ( ) ;
102102 expect ( store1 . getContent ( ) ) . toEqual ( [ { t1 : { r1 : { c1 : 1 } } } , { v1 : 1 } ] ) ;
103103 } ) ;
104+
105+ test ( 'persister after data' , async ( ) => {
106+ docHandler1 . change (
107+ ( doc : any ) => ( doc [ 'tinybase' ] = { t : { t1 : { r1 : { c1 : 1 } } } , v : { v1 : 1 } } ) ,
108+ ) ;
109+ const store2 = createStore ( ) ;
110+ const persister2 = createAutomergePersister ( store2 , docHandler1 ) ;
111+ await persister2 . load ( ) ;
112+ expect ( store2 . getContent ( ) ) . toEqual ( [ { t1 : { r1 : { c1 : 1 } } } , { v1 : 1 } ] ) ;
113+ } ) ;
104114} ) ;
105115
106116describe ( 'Two stores, one doc' , ( ) => {
You can’t perform that action at this time.
0 commit comments