Pārlūkot izejas kodu

Use a factory interface instead of a function for `IModelDB` creation.

Ian Rose 8 gadi atpakaļ
vecāks
revīzija
5bd29e884a

+ 11 - 0
packages/coreutils/src/modeldb.ts

@@ -623,4 +623,15 @@ namespace ModelDB {
      */
     baseDB?: ModelDB;
   }
+
+  /**
+   * A factory interface for creating `IModelDB` objects.
+   */
+  export
+  interface IFactory {
+    /**
+     * Create a new `IModelDB` instance.
+     */
+    createNew(path: string): IModelDB;
+  }
 }

+ 3 - 3
packages/docmanager/src/manager.ts

@@ -34,7 +34,7 @@ import {
 } from '@jupyterlab/apputils';
 
 import {
-  IModelDB
+  ModelDB
 } from '@jupyterlab/coreutils';
 
 import {
@@ -409,7 +409,7 @@ class DocumentManager implements IDisposable {
   private _contexts: Private.IContext[] = [];
   private _opener: DocumentManager.IWidgetOpener = null;
   private _activateRequested = new Signal<this, string>(this);
-  private _modelDBFactory: (path: string) => IModelDB = null;
+  private _modelDBFactory: ModelDB.IFactory = null;
 }
 
 
@@ -441,7 +441,7 @@ namespace DocumentManager {
     /**
      * An `IModelDB` backend factory method.
      */
-    modelDBFactory?: (path: string) => IModelDB;
+    modelDBFactory?: ModelDB.IFactory;
   }
 
   /**

+ 3 - 3
packages/docregistry/src/context.ts

@@ -26,7 +26,7 @@ import {
 } from '@jupyterlab/apputils';
 
 import {
-  PathExt, URLExt, IModelDB
+  PathExt, URLExt, IModelDB, ModelDB
 } from '@jupyterlab/coreutils';
 
 import {
@@ -53,7 +53,7 @@ class Context<T extends DocumentRegistry.IModel> implements DocumentRegistry.ICo
     let lang = this._factory.preferredLanguage(ext);
 
     if (options.modelDBFactory) {
-      this._modelDB = options.modelDBFactory(this._path);
+      this._modelDB = options.modelDBFactory.createNew(this._path);
       this._model = this._factory.createNew(lang, this._modelDB);
     } else {
       this._model = this._factory.createNew(lang);
@@ -501,7 +501,7 @@ export namespace Context {
     /**
      * An IModelDB factory method which may be used for the document.
      */
-    modelDBFactory?: (path: string) => IModelDB;
+    modelDBFactory?: ModelDB.IFactory;
 
     /**
      * An optional callback for opening sibling widgets.