Kaynağa Gözat

Update state database instantiation options to take a window name string instead of a promise.

Afshin Darian 7 yıl önce
ebeveyn
işleme
49a5fcb165

+ 2 - 1
packages/apputils-extension/src/index.ts

@@ -313,7 +313,8 @@ const state: JupyterLabPlugin<IStateDB> = {
     const transform = new PromiseDelegate<StateDB.DataTransform>();
     const state = new StateDB({
       namespace: info.namespace,
-      transform: transform.promise
+      transform: transform.promise,
+      windowName: resolver.name
     });
 
     commands.addCommand(CommandIDs.recoverState, {

+ 22 - 25
packages/coreutils/src/statedb.ts

@@ -102,33 +102,30 @@ class StateDB implements IStateDB {
 
     this.namespace = namespace;
 
-    // Retrieve the window name, which is used as a namespace prefix.
-    this._ready = (windowName || Promise.resolve('')).then(name => {
-      this._window = name;
+    this._window = windowName || '';
+    this._ready = (transform || Promise.resolve(null)).then(transformation => {
 
-      if (!transform) {
+      if (!transformation) {
         return;
       }
 
-      return transform.then(transformation => {
-        const { contents, type } = transformation;
-
-        switch (type) {
-          case 'cancel':
-            return;
-          case 'clear':
-            this._clear();
-            return;
-          case 'merge':
-            this._merge(contents || { });
-            return;
-          case 'overwrite':
-            this._overwrite(contents || { });
-            return;
-          default:
-            return;
-        }
-      });
+      const { contents, type } = transformation;
+
+      switch (type) {
+        case 'cancel':
+          return;
+        case 'clear':
+          this._clear();
+          return;
+        case 'merge':
+          this._merge(contents || { });
+          return;
+        case 'overwrite':
+          this._overwrite(contents || { });
+          return;
+        default:
+          return;
+      }
     });
   }
 
@@ -455,7 +452,7 @@ namespace StateDB {
     transform?: Promise<DataTransform>;
 
     /**
-     * An optional promise that resolves to a name for the application window.
+     * An optional name for the application window.
      *
      * #### Notes
      * In environments where multiple windows can instantiate a state database,
@@ -463,7 +460,7 @@ namespace StateDB {
      * local storage that is shared by all windows. In JupyterLab, this window
      * name is generated by the `IWindowResolver` extension.
      */
-    windowName?: Promise<string>;
+    windowName?: string;
   }
 }