Преглед изворни кода

Switch to displaying payloads by spoofing them as display_data, fix tests.

Afshin Darian пре 8 година
родитељ
комит
11fe9c438a
3 измењених фајлова са 22 додато и 50 уклоњено
  1. 2 24
      src/notebook/notebook/nbformat.ts
  2. 20 24
      src/notebook/output-area/model.ts
  3. 0 2
      src/notebook/output-area/widget.ts

+ 2 - 24
src/notebook/notebook/nbformat.ts

@@ -254,7 +254,7 @@ namespace nbformat {
    * The valid output types.
    */
   export
-  type OutputType = 'execute_reply' | 'execute_result' | 'display_data' | 'stream' | 'error';
+  type OutputType = 'execute_result' | 'display_data' | 'stream' | 'error';
 
 
   /**
@@ -269,28 +269,6 @@ namespace nbformat {
   }
 
 
-  /**
-   * Result of a non-execution reply to a code cell execution.
-   */
-  export
-  interface IExecuteReply extends IBaseOutput {
-    /**
-     * Type of cell output.
-     */
-    output_type: 'execute_reply';
-
-    /**
-     * A result's prompt number.
-     */
-    execution_count: number;
-
-    /**
-     * A mime-type keyed dictionary of data.
-     */
-    data: MimeBundle;
-  }
-
-
   /**
    * Result of executing a code cell.
    */
@@ -393,5 +371,5 @@ namespace nbformat {
    * An output union type.
    */
   export
-  type IOutput = IExecuteReply | IExecuteResult | IDisplayData | IStream | IError;
+  type IOutput = IExecuteResult | IDisplayData | IStream | IError;
 }

+ 20 - 24
src/notebook/output-area/model.ts

@@ -128,7 +128,6 @@ class OutputAreaModel implements IDisposable {
     } else {
       switch (value.output_type) {
       case 'stream':
-      case 'execute_reply':
       case 'execute_result':
       case 'display_data':
       case 'error':
@@ -208,30 +207,27 @@ class OutputAreaModel implements IDisposable {
       };
       // Handle the execute reply.
       future.onReply = (msg: KernelMessage.IExecuteReplyMsg) => {
-        let msgType = msg.header.msg_type;
-        switch (msgType) {
-        case 'execute_reply':
-          let content = msg.content as KernelMessage.IExecuteOkReply;
-          let payload = content && content.payload;
-          if (!payload) {
-            break;
-          }
-          let page = payload.filter(i => (i as any).source === 'page')[0];
-          if (!page) {
-            break;
-          }
-          let model: nbformat.IOutput = {
-            execution_count: msg.content.execution_count,
-            output_type: 'execute_reply',
-            data: (page as any).data as nbformat.MimeBundle,
-            metadata: {}
-          };
-          this.add(model);
-          break;
-        default:
-          break;
-        }
         resolve(msg);
+        // API responses that contain a pager are special cased and their type
+        // is overriden from 'execute_reply' to 'display_data' in order to
+        // render output.
+        let content = msg.content as KernelMessage.IExecuteOkReply;
+        let payload = content && content.payload;
+        if (!payload || !payload.length) {
+          return;
+        }
+        let pages = payload.filter(i => (i as any).source === 'page');
+        if (!pages.length) {
+          return;
+        }
+        let page = JSON.parse(JSON.stringify(pages[0]));
+        let model: nbformat.IOutput = {
+          execution_count: msg.content.execution_count,
+          output_type: 'display_data',
+          data: (page as any).data as nbformat.MimeBundle,
+          metadata: {}
+        };
+        this.add(model);
       };
       // Handle stdin.
       future.onStdin = (msg: KernelMessage.IStdinMessage) => {

+ 0 - 2
src/notebook/output-area/widget.ts

@@ -759,7 +759,6 @@ class OutputWidget extends Widget {
 
     // Add classes and output prompt as necessary.
     switch (output.output_type) {
-    case 'execute_reply':
     case 'execute_result':
       child.addClass(EXECUTE_CLASS);
       let count = (output as nbformat.IExecuteResult).execution_count;
@@ -818,7 +817,6 @@ class OutputWidget extends Widget {
   protected getBundle(output: nbformat.IOutput): nbformat.MimeBundle {
     let bundle: nbformat.MimeBundle;
     switch (output.output_type) {
-    case 'execute_reply':
     case 'execute_result':
       bundle = (output as nbformat.IExecuteResult).data;
       break;