Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allows _attrs to be null IJupyterYDoc #21

Merged
merged 1 commit into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<IJupyterYDoc, MapChange> {
Expand All @@ -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);
}
}
Expand All @@ -123,7 +126,7 @@ export class JupyterYDoc implements IJupyterYDoc {
this._attrsChanged.emit(event.keys);
};

private _attrs: Y.Map<string>;
private _attrs?: Y.Map<string>;
private _attrsChanged = new Signal<IJupyterYDoc, MapChange>(this);

private _isDisposed = false;
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down