@@ -101,10 +101,10 @@ export class YjsService
101101 const edges = await this . edgeService . findEdges ( ) ;
102102 const nodesMap = doc . getMap ( 'nodes' ) ;
103103 const title = doc . getMap ( 'title' ) ;
104- const emoji = doc . getText ( 'emoji' ) ;
104+ const emoji = doc . getMap ( 'emoji' ) ;
105105 const edgesMap = doc . getMap ( 'edges' ) ;
106106
107- this . initializeYNodeMap ( nodes , nodesMap ) ;
107+ this . initializeYNodeMap ( nodes , nodesMap , title , emoji ) ;
108108 this . initializeYEdgeMap ( edges , edgesMap ) ;
109109
110110 // title의 변경 사항을 감지한다.
@@ -130,6 +130,7 @@ export class YjsService
130130 } ) ;
131131 // node의 변경 사항을 감지한다.
132132 nodesMap . observe ( async ( event ) => {
133+ console . log ( 'nodesmap' , nodesMap . toJSON ( ) ) ;
133134 console . log ( '노드 개수' , event . changes . keys ) ;
134135 for ( const [ key , change ] of event . changes . keys ) {
135136 if ( change . action === 'update' ) {
@@ -167,12 +168,17 @@ export class YjsService
167168 }
168169
169170 // YMap에 노드 정보를 넣어준다.
170- initializeYNodeMap ( nodes : Node [ ] , yMap : Y . Map < unknown > ) : void {
171+ initializeYNodeMap (
172+ nodes : Node [ ] ,
173+ yNodeMap : Y . Map < unknown > ,
174+ yTitleMap : Y . Map < unknown > ,
175+ yEmojiMap : Y . Map < unknown > ,
176+ ) : void {
171177 nodes . forEach ( ( node ) => {
172178 const nodeId = node . id . toString ( ) ; // id를 string으로 변환
173179
174180 // Y.Map에 데이터를 삽입
175- yMap . set ( nodeId , {
181+ yNodeMap . set ( nodeId , {
176182 id : nodeId ,
177183 type : 'note' ,
178184 data : {
@@ -194,15 +200,14 @@ export class YjsService
194200 const yTitleText = new Y . Text ( ) ;
195201 yTitleText . insert ( 0 , node . page . title ) ;
196202 // Y.Map에 데이터를 삽입
197- yMap . set ( `title_${ pageId } ` , yTitleText ) ;
203+ yTitleMap . set ( `title_${ pageId } ` , yTitleText ) ;
198204
199205 // Y.Text emoji에 데이터 삽입
200206 const yEmojiText = new Y . Text ( ) ;
201207 const emoji = node . page . emoji ?? '📄' ;
202- console . log ( node . page ) ;
203208 yEmojiText . insert ( 0 , emoji ) ;
204209 // Y.Map에 데이터를 삽입
205- yMap . set ( `emoji_${ pageId } ` , yEmojiText ) ;
210+ yEmojiMap . set ( `emoji_${ pageId } ` , yEmojiText ) ;
206211 } ) ;
207212 }
208213
0 commit comments