Skip to content

Commit 9d81d40

Browse files
committed
refactor: CustomDoc 클래스 추가
1 parent debf79b commit 9d81d40

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

apps/backend/src/yjs/yjs.service.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ type YMapEdge = {
3737
sourceHandle: string;
3838
targetHandle: string;
3939
};
40+
41+
// Y.Doc에는 name 컬럼이 없어서 생성했습니다.
42+
class CustomDoc extends Y.Doc {
43+
name: string;
44+
45+
constructor(name: string) {
46+
super();
47+
this.name = name;
48+
}
49+
}
4050
@WebSocketGateway(1234)
4151
export class YjsService
4252
implements OnGatewayInit, OnGatewayConnection, OnGatewayDisconnect
@@ -65,14 +75,15 @@ export class YjsService
6575

6676
this.ysocketio.initialize();
6777

68-
this.ysocketio.on('document-loaded', (doc: any) => {
78+
this.ysocketio.on('document-loaded', (doc: Y.Doc) => {
6979
const nodes = doc.getMap('nodes');
7080
const edges = doc.getMap('edges');
7181
const editorDoc = doc.getXmlFragment('default');
7282

7383
// page content의 변경 사항을 감지한다.
7484
editorDoc.observeDeep(() => {
75-
const pageId = editorDoc.doc.name.split('-')[1];
85+
const document = editorDoc.doc as CustomDoc;
86+
const pageId = parseInt(document.name.split('-')[1]);
7687
this.pageService.updatePage(
7788
pageId,
7889
JSON.parse(JSON.stringify(yXmlFragmentToProsemirrorJSON(editorDoc))),

0 commit comments

Comments
 (0)