Browse Source

Add isReady to context

Steven Silvester 8 năm trước cách đây
mục cha
commit
17fdb16a2a
3 tập tin đã thay đổi với 24 bổ sung5 xóa
  1. 9 0
      src/docregistry/context.ts
  2. 5 0
      src/docregistry/registry.ts
  3. 10 5
      src/notebook/notebook/panel.ts

+ 9 - 0
src/docregistry/context.ts

@@ -158,6 +158,13 @@ class Context<T extends DocumentRegistry.IModel> implements DocumentRegistry.ICo
     return this._manager.specs;
   }
 
+  /**
+   * Whether the context is ready.
+   */
+  get isReady(): boolean {
+    return this._isReady;
+  }
+
  /**
   * A promise that is fulfilled when the context is ready.
   */
@@ -459,6 +466,7 @@ class Context<T extends DocumentRegistry.IModel> implements DocumentRegistry.ICo
         return this.createCheckpoint();
       }
     }).then(() => {
+      this._isReady = true;
       this._populatedPromise.resolve(void 0);
     });
   }
@@ -473,6 +481,7 @@ class Context<T extends DocumentRegistry.IModel> implements DocumentRegistry.ICo
   private _readyPromise: Promise<void>;
   private _populatedPromise = new utils.PromiseDelegate<void>();
   private _isPopulated = false;
+  private _isReady = false;
 }
 
 

+ 5 - 0
src/docregistry/registry.ts

@@ -624,6 +624,11 @@ namespace DocumentRegistry {
      */
     readonly contentsModel: Contents.IModel;
 
+    /**
+     * Whether the context is ready.
+     */
+    readonly isReady: boolean;
+
     /**
      * A promise that is fulfilled when the context is ready.
      */

+ 10 - 5
src/notebook/notebook/panel.ts

@@ -305,16 +305,21 @@ class NotebookPanel extends Widget {
 
     // Handle context initialization.
     newValue.ready().then(() => {
-      let model = newValue.model;
-      // Clear the undo state of the cells.
-      if (model) {
-        model.cells.clearUndo();
-      }
       if (!newValue.kernel) {
         newValue.startDefaultKernel();
       }
     });
 
+    if (!newValue.isReady) {
+      newValue.ready().then(() => {
+        let model = newValue.model;
+        // Clear the undo state of the cells.
+        if (model) {
+          model.cells.clearUndo();
+        }
+      });
+    }
+
     // Handle the document title.
     this.onPathChanged(context, context.path);
     context.pathChanged.connect(this.onPathChanged, this);