|
@@ -19,6 +19,7 @@ import {
|
|
|
IModelDB,
|
|
|
IObservableJSON,
|
|
|
IObservableList,
|
|
|
+ IObservableMap,
|
|
|
IObservableUndoableList,
|
|
|
ModelDB
|
|
|
} from '@jupyterlab/observables';
|
|
@@ -28,10 +29,12 @@ import {
|
|
|
nullTranslator,
|
|
|
TranslationBundle
|
|
|
} from '@jupyterlab/translation';
|
|
|
-import { UUID } from '@lumino/coreutils';
|
|
|
+import { JSONObject, ReadonlyPartialJSONValue, UUID } from '@lumino/coreutils';
|
|
|
import { ISignal, Signal } from '@lumino/signaling';
|
|
|
import { CellList } from './celllist';
|
|
|
|
|
|
+const UNSHARED_KEYS = ['kernelspec', 'language_info'];
|
|
|
+
|
|
|
/**
|
|
|
* The definition of a model object for a notebook widget.
|
|
|
*/
|
|
@@ -105,7 +108,7 @@ export class NotebookModel implements INotebookModel {
|
|
|
metadata.set('language_info', { name });
|
|
|
}
|
|
|
this._ensureMetadata();
|
|
|
- metadata.changed.connect(this.triggerContentChange, this);
|
|
|
+ metadata.changed.connect(this._onMetadataChanged, this);
|
|
|
this._deletedCells = [];
|
|
|
|
|
|
this.sharedModel.changed.connect(this._onStateChanged, this);
|
|
@@ -428,6 +431,27 @@ close the notebook without saving it.`,
|
|
|
this.triggerStateChange(value);
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+ if (changes.metadataChange) {
|
|
|
+ const metadata = changes.metadataChange.newValue as JSONObject;
|
|
|
+ this._modelDBMutex(() => {
|
|
|
+ Object.entries(metadata).forEach(([key, value]) => {
|
|
|
+ this.metadata.set(key, value);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private _onMetadataChanged(
|
|
|
+ metadata: IObservableJSON,
|
|
|
+ change: IObservableMap.IChangedArgs<ReadonlyPartialJSONValue | undefined>
|
|
|
+ ): void {
|
|
|
+ if (!UNSHARED_KEYS.includes(change.key)) {
|
|
|
+ this._modelDBMutex(() => {
|
|
|
+ this.sharedModel.updateMetadata(metadata.toJSON());
|
|
|
+ });
|
|
|
+ }
|
|
|
+ this.triggerContentChange();
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -475,6 +499,11 @@ close the notebook without saving it.`,
|
|
|
*/
|
|
|
readonly sharedModel = models.YNotebook.create() as models.ISharedNotebook;
|
|
|
|
|
|
+ /**
|
|
|
+ * A mutex to update the shared model.
|
|
|
+ */
|
|
|
+ protected readonly _modelDBMutex = models.createMutex();
|
|
|
+
|
|
|
/**
|
|
|
* The underlying `IModelDB` instance in which model
|
|
|
* data is stored.
|