Skip to content

Commit 2191225

Browse files
authored
Allow _attrs to be null IJupyterYDoc (#21)
1 parent e181feb commit 2191225

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

src/model.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,11 @@ export class JupyterYDoc implements IJupyterYDoc {
7979
get ydoc(): Y.Doc {
8080
return this._ydoc;
8181
}
82-
get attrs(): JSONObject {
83-
return JSONExt.deepCopy(this._attrs.toJSON());
82+
get attrs(): JSONObject | null {
83+
if (this._attrs) {
84+
return JSONExt.deepCopy(this._attrs.toJSON());
85+
}
86+
return null;
8487
}
8588

8689
get attrsChanged(): ISignal<IJupyterYDoc, MapChange> {
@@ -99,22 +102,22 @@ export class JupyterYDoc implements IJupyterYDoc {
99102
if (this._isDisposed) {
100103
return;
101104
}
102-
this._attrs.unobserve(this._attrsObserver);
105+
this._attrs?.unobserve(this._attrsObserver);
103106
this._disposed.emit();
104107
Signal.clearData(this);
105108
this._isDisposed = true;
106109
}
107110

108111
getAttr(key: string): any {
109-
return this._attrs.get(key);
112+
return this._attrs?.get(key);
110113
}
111114

112115
setAttr(key: string, value: any): void {
113-
this._attrs.set(key, value);
116+
this._attrs?.set(key, value);
114117
}
115118

116119
removeAttr(key: string): void {
117-
if (this._attrs.has(key)) {
120+
if (this._attrs?.has(key)) {
118121
this._attrs.delete(key);
119122
}
120123
}
@@ -123,7 +126,7 @@ export class JupyterYDoc implements IJupyterYDoc {
123126
this._attrsChanged.emit(event.keys);
124127
};
125128

126-
private _attrs: Y.Map<string>;
129+
private _attrs?: Y.Map<string>;
127130
private _attrsChanged = new Signal<IJupyterYDoc, MapChange>(this);
128131

129132
private _isDisposed = false;

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export interface IJupyterYDocChange {
1010
}
1111

1212
export interface IJupyterYDoc extends IDisposable {
13-
attrs: JSONObject;
13+
attrs: JSONObject | null;
1414

1515
getAttr(key: string): any;
1616
setAttr(key: string, value: any): void;

0 commit comments

Comments
 (0)