Ver Fonte

More fixes in docregistry

Steven Silvester há 7 anos atrás
pai
commit
b8df6fbc57

+ 5 - 4
packages/docregistry/src/context.ts

@@ -115,12 +115,13 @@ class Context<T extends DocumentRegistry.IModel> implements DocumentRegistry.ICo
   }
 
   /**
-   * The current contents model associated with the document
+   * The current contents model associated with the document.
    *
    * #### Notes
-   * The model will have an  empty `contents` field.
+   * The contents model will be null until the context is populated.
+   * It will have an  empty `contents` field.
    */
-  get contentsModel(): Contents.IModel {
+  get contentsModel(): Contents.IModel | null {
     return this._contentsModel;
   }
 
@@ -458,7 +459,7 @@ class Context<T extends DocumentRegistry.IModel> implements DocumentRegistry.ICo
   private _modelDB: IModelDB;
   private _path = '';
   private _factory: DocumentRegistry.IModelFactory<T>;
-  private _contentsModel: Contents.IModel;
+  private _contentsModel: Contents.IModel | null = null;
   private _readyPromise: Promise<void>;
   private _populatedPromise = new PromiseDelegate<void>();
   private _isPopulated = false;

+ 7 - 5
packages/docregistry/src/registry.ts

@@ -58,16 +58,17 @@ class DocumentRegistry implements IDisposable {
    * Get whether the document registry has been disposed.
    */
   get isDisposed(): boolean {
-    return this._widgetFactories === null;
+    return this._isDisposed;
   }
 
   /**
    * Dispose of the resources held by the document registery.
    */
   dispose(): void {
-    if (this._widgetFactories === null) {
+    if (this.isDisposed) {
       return;
     }
+    this._isDisposed = true;
     for (let modelName in this._modelFactories) {
       this._modelFactories[modelName].dispose();
     }
@@ -520,6 +521,7 @@ class DocumentRegistry implements IDisposable {
   private _creators: DocumentRegistry.IFileCreator[] = [];
   private _extenders: { [key: string] : DocumentRegistry.WidgetExtension[] } = Object.create(null);
   private _changed = new Signal<this, DocumentRegistry.IChangedArgs>(this);
+  private _isDisposed = false;
 }
 
 
@@ -649,10 +651,10 @@ namespace DocumentRegistry {
      * The current contents model associated with the document
      *
      * #### Notes
-     * The model will have an empty `contents` field.
-     * It will be `null` until the context is ready.
+     * The contents model will be null until the context is ready.
+     * It will have an  empty `contents` field.
      */
-    readonly contentsModel: Contents.IModel;
+    readonly contentsModel: Contents.IModel | null;
 
     /**
      * Whether the context is ready.