@@ -8,9 +8,7 @@ import { IJupyterYDoc, IJupyterYModel } from './types';
8
8
export class JupyterYModel implements IJupyterYModel {
9
9
constructor ( commMetadata : { [ key : string ] : any } ) {
10
10
this . _yModelName = commMetadata . ymodel_name ;
11
- this . ydocFactory ( commMetadata ) . then ( async ( ydoc ) => {
12
- this . _sharedModel = await this . sharedModelFactory ( commMetadata , ydoc ) ;
13
-
11
+ this . initialize ( commMetadata ) . then ( ( ) => {
14
12
this . _ready . resolve ( ) ;
15
13
} ) ;
16
14
}
@@ -23,6 +21,18 @@ export class JupyterYModel implements IJupyterYModel {
23
21
return this . _sharedModel ;
24
22
}
25
23
24
+ get ydoc ( ) : Y . Doc {
25
+ return this . _ydoc ;
26
+ }
27
+
28
+ protected set sharedModel ( value : IJupyterYDoc ) {
29
+ this . _sharedModel = value ;
30
+ }
31
+
32
+ protected set ydoc ( value : Y . Doc ) {
33
+ this . _ydoc = value ;
34
+ }
35
+
26
36
get sharedAttrsChanged ( ) : ISignal < IJupyterYDoc , MapChange > {
27
37
return this . sharedModel . attrsChanged ;
28
38
}
@@ -39,12 +49,13 @@ export class JupyterYModel implements IJupyterYModel {
39
49
return this . _ready . promise ;
40
50
}
41
51
42
- async ydocFactory ( commMetadata : { [ key : string ] : any } ) : Promise < Y . Doc > {
43
- return new Y . Doc ( ) ;
52
+ protected async initialize ( commMetadata : { [ key : string ] : any } ) {
53
+ this . ydoc = this . ydocFactory ( commMetadata ) ;
54
+ this . sharedModel = new JupyterYDoc ( commMetadata , this . _ydoc ) ;
44
55
}
45
56
46
- async sharedModelFactory ( commMetadata : { [ key : string ] : any } , ydoc : Y . Doc ) {
47
- return new JupyterYDoc ( commMetadata , ydoc ) ;
57
+ ydocFactory ( commMetadata : { [ key : string ] : any } ) : Y . Doc {
58
+ return new Y . Doc ( ) ;
48
59
}
49
60
50
61
dispose ( ) : void {
@@ -65,6 +76,8 @@ export class JupyterYModel implements IJupyterYModel {
65
76
this . sharedModel . removeAttr ( key ) ;
66
77
}
67
78
79
+ private _ydoc : Y . Doc ;
80
+
68
81
private _yModelName : string ;
69
82
private _sharedModel : IJupyterYDoc ;
70
83
0 commit comments