Browse Source

Make text model factory optional

Steven Silvester 7 years ago
parent
commit
07096ec17f
2 changed files with 11 additions and 7 deletions
  1. 2 4
      packages/application/src/index.ts
  2. 9 3
      packages/docregistry/src/registry.ts

+ 2 - 4
packages/application/src/index.ts

@@ -6,7 +6,7 @@ import {
 } from '@jupyterlab/apputils';
 
 import {
-  Base64ModelFactory, DocumentRegistry, TextModelFactory
+  Base64ModelFactory, DocumentRegistry
 } from '@jupyterlab/docregistry';
 
 import {
@@ -69,9 +69,7 @@ class JupyterLab extends Application<ApplicationShell> {
     let initialFactories = defaultRendererFactories;
     this.rendermime = new RenderMime({ initialFactories, linkHandler });
 
-    let registry = this.docRegistry = new DocumentRegistry({
-      textModelFactory: new TextModelFactory()
-    });
+    let registry = this.docRegistry = new DocumentRegistry();
     DocumentRegistry.defaultFileTypes.forEach(ft => {
       registry.addFileType(ft);
     });

+ 9 - 3
packages/docregistry/src/registry.ts

@@ -37,6 +37,10 @@ import {
   IChangedArgs as IChangedArgsGeneric, PathExt, IModelDB
 } from '@jupyterlab/coreutils';
 
+import {
+  TextModelFactory
+} from './default';
+
 
 /**
  * The document registry.
@@ -46,11 +50,13 @@ class DocumentRegistry implements IDisposable {
   /**
    * Construct a new document registry.
    */
-  constructor(options: DocumentRegistry.IOptions) {
+  constructor(options: DocumentRegistry.IOptions = {}) {
     if (options.textModelFactory.name !== 'text') {
       throw new Error('Text model factory must have the name `text`');
     }
-    this._modelFactories['text'] = options.textModelFactory;
+    this._modelFactories['text'] = (
+      options.textModelFactory || new TextModelFactory()
+    );
   }
 
   /**
@@ -592,7 +598,7 @@ namespace DocumentRegistry {
     /**
      * The text model factory for the registry.
      */
-    textModelFactory: ModelFactory;
+    textModelFactory?: ModelFactory;
   }
 
   /**