Przeglądaj źródła

Add when promise.

Afshin Darian 7 lat temu
rodzic
commit
5f636d7936

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

@@ -61,8 +61,9 @@ const plugin: JupyterLabPlugin<void> = {
         }
 
         const key = plugin.id;
+        const when = app.restored;
         const editor = new SettingEditor({
-          editorFactory, key, registry, state
+          editorFactory, key, registry, state, when
         });
 
         tracker.add(editor);

+ 13 - 1
packages/settingeditor-extension/src/settingeditor.ts

@@ -142,6 +142,11 @@ class SettingEditor extends Widget {
     const editor = this._editor = new PluginEditor({ editorFactory });
     const confirm = () => editor.confirm();
     const list = this._list = new PluginList({ confirm, registry });
+    const when = options.when;
+
+    if (when) {
+      this._when = Array.isArray(when) ? Promise.all(when) : when;
+    }
 
     layout.addWidget(panel);
     panel.addWidget(list);
@@ -226,8 +231,9 @@ class SettingEditor extends Widget {
 
     const { key, state } = this;
     const editor = this._editor;
+    const promises = [state.fetch(key), this._when];
 
-    return this._fetching = state.fetch(key).then(saved => {
+    return this._fetching = Promise.all(promises).then(([saved]) => {
       this._fetching = null;
 
       if (this._saving) {
@@ -357,6 +363,7 @@ class SettingEditor extends Widget {
   private _panel: SplitPanel;
   private _presets = { inner: DEFAULT_INNER, outer: DEFAULT_OUTER, plugin: '' };
   private _saving = false;
+  private _when: Promise<any>;
 }
 
 
@@ -389,6 +396,11 @@ namespace SettingEditor {
      * The state database used to store layout.
      */
     state: IStateDB;
+
+    /**
+     * The point after which the editor should restore its state.
+     */
+    when?: Promise<any> | Array<Promise<any>>;
   }
 }