Skip to content

Commit de8a892

Browse files
committed
Backward compat
1 parent 5cd6ed7 commit de8a892

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

src/model.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ import { IJupyterYDoc, IJupyterYModel } from './types';
88
export class JupyterYModel implements IJupyterYModel {
99
constructor(commMetadata: { [key: string]: any }) {
1010
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(() => {
1412
this._ready.resolve();
1513
});
1614
}
@@ -23,6 +21,18 @@ export class JupyterYModel implements IJupyterYModel {
2321
return this._sharedModel;
2422
}
2523

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+
2636
get sharedAttrsChanged(): ISignal<IJupyterYDoc, MapChange> {
2737
return this.sharedModel.attrsChanged;
2838
}
@@ -39,12 +49,13 @@ export class JupyterYModel implements IJupyterYModel {
3949
return this._ready.promise;
4050
}
4151

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);
4455
}
4556

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();
4859
}
4960

5061
dispose(): void {
@@ -65,6 +76,8 @@ export class JupyterYModel implements IJupyterYModel {
6576
this.sharedModel.removeAttr(key);
6677
}
6778

79+
private _ydoc: Y.Doc;
80+
6881
private _yModelName: string;
6982
private _sharedModel: IJupyterYDoc;
7083

0 commit comments

Comments
 (0)