|
@@ -1,6 +1,10 @@
|
|
// Copyright (c) Jupyter Development Team.
|
|
// Copyright (c) Jupyter Development Team.
|
|
// Distributed under the terms of the Modified BSD License.
|
|
// Distributed under the terms of the Modified BSD License.
|
|
|
|
|
|
|
|
+import {
|
|
|
|
+ JSONObject
|
|
|
|
+} from 'phosphor/lib/algorithm/json';
|
|
|
|
+
|
|
import {
|
|
import {
|
|
JupyterLabPlugin
|
|
JupyterLabPlugin
|
|
} from '../application';
|
|
} from '../application';
|
|
@@ -20,7 +24,23 @@ import {
|
|
export
|
|
export
|
|
const stateProvider: JupyterLabPlugin<IStateDB> = {
|
|
const stateProvider: JupyterLabPlugin<IStateDB> = {
|
|
id: 'jupyter.services.statedb',
|
|
id: 'jupyter.services.statedb',
|
|
- activate: (): IStateDB => new StateDB(),
|
|
|
|
|
|
+ activate: activateState,
|
|
autoStart: true,
|
|
autoStart: true,
|
|
provides: IStateDB
|
|
provides: IStateDB
|
|
};
|
|
};
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+function activateState(): Promise<IStateDB> {
|
|
|
|
+ let state = new StateDB();
|
|
|
|
+ let version = (window as any).jupyter.version;
|
|
|
|
+ let key = 'statedb:version';
|
|
|
|
+ let fetch = state.fetch(key);
|
|
|
|
+ let save = () => state.save(key, { version });
|
|
|
|
+ let overwrite = () => state.clear().then(save);
|
|
|
|
+ let check = (value: JSONObject) => {
|
|
|
|
+ if (!value || (value as any).version !== version) {
|
|
|
|
+ return overwrite();
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+ return fetch.then(check, overwrite).then(() => state);
|
|
|
|
+}
|