Skip to content

Commit 7080c66

Browse files
authored
Make YDocument a IObservableDisposable (#108)
1 parent 334a8ad commit 7080c66

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

javascript/src/api.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import type {
2020
JSONValue,
2121
PartialJSONValue
2222
} from '@lumino/coreutils';
23-
import type { IDisposable, IObservableDisposable } from '@lumino/disposable';
23+
import type { IObservableDisposable } from '@lumino/disposable';
2424
import type { ISignal } from '@lumino/signaling';
2525

2626
/**
@@ -44,7 +44,7 @@ export type MapChanges = Map<
4444
/**
4545
* ISharedBase defines common operations that can be performed on any shared object.
4646
*/
47-
export interface ISharedBase extends IDisposable {
47+
export interface ISharedBase extends IObservableDisposable {
4848
/**
4949
* Undo an operation.
5050
*/
@@ -387,8 +387,7 @@ export namespace SharedCell {
387387
*/
388388
export interface ISharedBaseCell<
389389
Metadata extends nbformat.IBaseCellMetadata = nbformat.IBaseCellMetadata
390-
> extends ISharedText,
391-
IObservableDisposable {
390+
> extends ISharedText {
392391
/**
393392
* The type of the cell.
394393
*/

javascript/src/ymodels.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ export class YDocument<T extends DocumentChange> implements ISharedDocument {
9292
return this._changed;
9393
}
9494

95+
/**
96+
* A signal emitted when the document is disposed.
97+
*/
98+
get disposed(): ISignal<this, void> {
99+
return this._disposed;
100+
}
101+
95102
/**
96103
* Whether the document is disposed or not.
97104
*/
@@ -132,6 +139,7 @@ export class YDocument<T extends DocumentChange> implements ISharedDocument {
132139
this.awareness.destroy();
133140
this.undoManager.destroy();
134141
this.ydoc.destroy();
142+
this._disposed.emit();
135143
Signal.clearData(this);
136144
}
137145

@@ -209,6 +217,7 @@ export class YDocument<T extends DocumentChange> implements ISharedDocument {
209217

210218
protected _changed = new Signal<this, T>(this);
211219
private _isDisposed = false;
220+
private _disposed = new Signal<this, void>(this);
212221
}
213222

214223
/**

javascript/test/ymodels.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@ describe('@jupyter/ydoc', () => {
1313
});
1414
});
1515

16+
describe('#disposed', () => {
17+
test('should be emitted when the document is disposed', () => {
18+
const notebook = new YNotebook();
19+
let disposed = false;
20+
notebook.disposed.connect(() => {
21+
disposed = true;
22+
});
23+
notebook.dispose();
24+
expect(disposed).toEqual(true);
25+
});
26+
});
27+
1628
describe('metadata', () => {
1729
test('should get metadata', () => {
1830
const notebook = new YNotebook();

0 commit comments

Comments
 (0)