diff --git a/src/model.ts b/src/model.ts index 25583a3..8cdf613 100644 --- a/src/model.ts +++ b/src/model.ts @@ -79,8 +79,11 @@ export class JupyterYDoc implements IJupyterYDoc { get ydoc(): Y.Doc { return this._ydoc; } - get attrs(): JSONObject { - return JSONExt.deepCopy(this._attrs.toJSON()); + get attrs(): JSONObject | null { + if (this._attrs) { + return JSONExt.deepCopy(this._attrs.toJSON()); + } + return null; } get attrsChanged(): ISignal { @@ -99,22 +102,22 @@ export class JupyterYDoc implements IJupyterYDoc { if (this._isDisposed) { return; } - this._attrs.unobserve(this._attrsObserver); + this._attrs?.unobserve(this._attrsObserver); this._disposed.emit(); Signal.clearData(this); this._isDisposed = true; } getAttr(key: string): any { - return this._attrs.get(key); + return this._attrs?.get(key); } setAttr(key: string, value: any): void { - this._attrs.set(key, value); + this._attrs?.set(key, value); } removeAttr(key: string): void { - if (this._attrs.has(key)) { + if (this._attrs?.has(key)) { this._attrs.delete(key); } } @@ -123,7 +126,7 @@ export class JupyterYDoc implements IJupyterYDoc { this._attrsChanged.emit(event.keys); }; - private _attrs: Y.Map; + private _attrs?: Y.Map; private _attrsChanged = new Signal(this); private _isDisposed = false; diff --git a/src/types.ts b/src/types.ts index f154db8..35190db 100644 --- a/src/types.ts +++ b/src/types.ts @@ -10,7 +10,7 @@ export interface IJupyterYDocChange { } export interface IJupyterYDoc extends IDisposable { - attrs: JSONObject; + attrs: JSONObject | null; getAttr(key: string): any; setAttr(key: string, value: any): void;