Sfoglia il codice sorgente

More string literals

Steven Silvester 9 anni fa
parent
commit
5714b4d60d

+ 8 - 23
src/notebook/cells/model.ts

@@ -26,26 +26,12 @@ import {
   Widget
 } from 'phosphor-widget';
 
+
 /**
- * An enum which describes the type of cell.
+ * A type which describes the type of cell.
  */
 export
-enum CellType {
-  /**
-   * The cell contains code input.
-   */
-  Code,
-
-  /**
-   * The cell contains markdown.
-   */
-  Markdown,
-
-  /**
-   * The cell contains raw text.
-   */
-  Raw
-}
+type CellType = "code" | "markdown" | "raw";
 
 
 /**
@@ -142,7 +128,6 @@ interface ICodeCellModel extends IBaseCellModel {
  */
 export
 interface IRawCellModel extends IBaseCellModel {
-
   /**
    * The raw cell format.
    */
@@ -290,7 +275,7 @@ class CodeCellModel extends BaseCellModel implements ICodeCellModel {
     Private.executionCountProperty.set(this, value);
   }
 
-  type: CellType = CellType.Code;
+  type: CellType = "code";
 }
 
 
@@ -322,7 +307,7 @@ class MarkdownCellModel extends BaseCellModel implements IMarkdownCellModel {
     if (!this.rendered) this.input.textEditor.select();
   }
 
-  type: CellType = CellType.Markdown;
+  type: CellType = "markdown";
 }
 
 /**
@@ -330,7 +315,7 @@ class MarkdownCellModel extends BaseCellModel implements IMarkdownCellModel {
   */
 export
 function isMarkdownCellModel(m: ICellModel): m is IMarkdownCellModel {
-  return (m.type === CellType.Markdown);
+  return (m.type === "markdown");
 }
 
 /**
@@ -338,7 +323,7 @@ function isMarkdownCellModel(m: ICellModel): m is IMarkdownCellModel {
   */
 export
 function isCodeCellModel(m: ICellModel): m is ICodeCellModel {
-  return (m.type === CellType.Code);
+  return (m.type === "code");
 }
 
 /**
@@ -346,7 +331,7 @@ function isCodeCellModel(m: ICellModel): m is ICodeCellModel {
   */
 export
 function isRawCellModel(m: ICellModel): m is IRawCellModel {
-  return (m.type === CellType.Raw);
+  return (m.type === "raw");
 }
 
 

+ 8 - 4
src/notebook/notebook/nbformat.ts

@@ -6,6 +6,10 @@ import {
   MimeBundle, OutputType
 } from '../output-area';
 
+import {
+  CellType
+} from '../cells';
+
 
 // In the notebook format *disk* representation, this would be string | string[]
 export type multilineString = string;
@@ -87,7 +91,7 @@ type Cell = BaseCell | RawCell | MarkdownCell | CodeCell;
 
 export
 interface BaseCell {
-  cell_type: string;
+  cell_type: CellType;
   source: multilineString;
   metadata: {
     name?: string;
@@ -97,7 +101,7 @@ interface BaseCell {
 
 export
 interface RawCell extends BaseCell {
-  cell_type: string; /*"raw"*/
+  cell_type: "raw";
   metadata: {
     format?: string;
   }
@@ -105,12 +109,12 @@ interface RawCell extends BaseCell {
 
 export
 interface MarkdownCell extends BaseCell {
-  cell_type: string; /*"markdown"*/
+  cell_type: "markdown";
 }
 
 export
 interface CodeCell extends BaseCell {
-  cell_type: string; /*"code"*/
+  cell_type: "code";
   metadata: {
     name?: string;
     tags?: string[];

+ 2 - 2
src/notebook/notebook/widget.ts

@@ -70,10 +70,10 @@ class NotebookWidget extends Panel {
     this._listdispose = follow<ICellModel>(model.cells, this, (c: ICellModel) => {
       let w: Widget;
       switch(c.type) {
-      case CellType.Code:
+      case "code":
         w = new CodeCellWidget(c as CodeCellModel);
         break;
-      case CellType.Markdown:
+      case "markdown":
         w = new MarkdownCellWidget(c as MarkdownCellModel);
         break;
       default:

+ 8 - 41
src/notebook/output-area/model.ts

@@ -61,12 +61,9 @@ class OutputBaseModel {
 export
 class DisplayDataModel extends OutputBaseModel {
   /**
-   * Construct a new display data model.
+   * The output type.
    */
-  constructor() {
-    super();
-    this.outputType = 'display_data';
-  }
+  outputType: OutputType = "display_data";
 
   /**
    * The raw data for the output.
@@ -77,11 +74,6 @@ class DisplayDataModel extends OutputBaseModel {
    * Metadata about the output.
    */
   metadata: any;
-
-  /**
-   * The output type.
-   */
-  outputType: "display_data";
 }
 
 
@@ -91,12 +83,9 @@ class DisplayDataModel extends OutputBaseModel {
 export
 class ExecuteResultModel extends OutputBaseModel {
   /**
-   * Construct a new execute result model.
+   * The output type.
    */
-  constructor() {
-    super();
-    this.outputType = 'execute_result';
-  }
+  outputType: OutputType = "execute_result";
 
   /**
    * The raw data for the output.
@@ -112,11 +101,6 @@ class ExecuteResultModel extends OutputBaseModel {
    * The current execution count.
    */
   executionCount: number; // this is also a property on the cell?
-
-  /**
-   * The output type.
-   */
-  outputType: "execute_result";
 }
 
 
@@ -127,13 +111,9 @@ class ExecuteResultModel extends OutputBaseModel {
 export
 class StreamModel extends OutputBaseModel {
   /**
-   * Construct a new stream model.
+   * The output type.
    */
-  constructor() {
-    super();
-    this.outputType = 'stream';
-  }
-
+  outputType: OutputType = "stream";
 
   /**
   * The type of stream.
@@ -144,11 +124,6 @@ class StreamModel extends OutputBaseModel {
   * The text from the stream.
   */
   text: string;
-
-  /**
-   * The output type.
-   */
-  outputType: "stream";
 }
 
 
@@ -163,12 +138,9 @@ function isStreamModel(model: OutputBaseModel): model is StreamModel {
 export
 class ExecuteErrorModel extends OutputBaseModel {
   /**
-   * Construct a new execute error model.
+   * The output type.
    */
-  constructor() {
-    super();
-    this.outputType = 'error';
-  }
+  outputType: OutputType = "error";
 
   /**
   * The name of the error.
@@ -187,11 +159,6 @@ class ExecuteErrorModel extends OutputBaseModel {
   * This is an array of strings that has been concatenated to a single string.
   */
   traceback: string;
-
-  /**
-   * The output type.
-   */
-  outputType: "error";
 }