1
1
import { MapChange } from '@jupyter/ydoc' ;
2
- import { JSONExt , JSONObject } from '@lumino/coreutils' ;
2
+ import { JSONExt , JSONObject , PromiseDelegate } from '@lumino/coreutils' ;
3
3
import { ISignal , Signal } from '@lumino/signaling' ;
4
4
import * as Y from 'yjs' ;
5
5
@@ -8,8 +8,9 @@ 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
- const ydoc = this . ydocFactory ( commMetadata ) ;
12
- this . _sharedModel = new JupyterYDoc ( commMetadata , ydoc ) ;
11
+ this . initialize ( commMetadata ) . then ( ( ) => {
12
+ this . _ready . resolve ( ) ;
13
+ } ) ;
13
14
}
14
15
15
16
get yModelName ( ) : string {
@@ -20,6 +21,18 @@ export class JupyterYModel implements IJupyterYModel {
20
21
return this . _sharedModel ;
21
22
}
22
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
+
23
36
get sharedAttrsChanged ( ) : ISignal < IJupyterYDoc , MapChange > {
24
37
return this . sharedModel . attrsChanged ;
25
38
}
@@ -32,6 +45,15 @@ export class JupyterYModel implements IJupyterYModel {
32
45
return this . _isDisposed ;
33
46
}
34
47
48
+ get ready ( ) : Promise < void > {
49
+ return this . _ready . promise ;
50
+ }
51
+
52
+ protected async initialize ( commMetadata : { [ key : string ] : any } ) {
53
+ this . ydoc = this . ydocFactory ( commMetadata ) ;
54
+ this . sharedModel = new JupyterYDoc ( commMetadata , this . _ydoc ) ;
55
+ }
56
+
35
57
ydocFactory ( commMetadata : { [ key : string ] : any } ) : Y . Doc {
36
58
return new Y . Doc ( ) ;
37
59
}
@@ -54,11 +76,15 @@ export class JupyterYModel implements IJupyterYModel {
54
76
this . sharedModel . removeAttr ( key ) ;
55
77
}
56
78
79
+ private _ydoc : Y . Doc ;
80
+
57
81
private _yModelName : string ;
58
82
private _sharedModel : IJupyterYDoc ;
59
83
60
84
private _isDisposed = false ;
61
85
86
+ private _ready : PromiseDelegate < void > = new PromiseDelegate < void > ( ) ;
87
+
62
88
private _disposed = new Signal < this, void > ( this ) ;
63
89
}
64
90
0 commit comments