Selaa lähdekoodia

set output_type without modifying original message

Mehmet Bektas 5 vuotta sitten
vanhempi
commit
17ff8e6c73

+ 4 - 2
packages/console/src/foreign.ts

@@ -116,8 +116,10 @@ export class ForeignHandler implements IDisposable {
         if (!cell) {
           return false;
         }
-        let output = msg.content as nbformat.IOutput;
-        output.output_type = msgType as nbformat.OutputType;
+        const output: nbformat.IOutput = {
+          ...msg.content,
+          output_type: msgType
+        };
         cell.model.outputs.add(output);
         parent.update();
         return true;

+ 2 - 4
packages/outputarea/src/widget.ts

@@ -491,8 +491,7 @@ export class OutputArea extends Widget {
       case 'display_data':
       case 'stream':
       case 'error':
-        output = msg.content as nbformat.IOutput;
-        output.output_type = msgType as nbformat.OutputType;
+        output = { ...msg.content, output_type: msgType };
         model.add(output);
         break;
       case 'clear_output':
@@ -500,8 +499,7 @@ export class OutputArea extends Widget {
         model.clear(wait);
         break;
       case 'update_display_data':
-        output = msg.content as nbformat.IOutput;
-        output.output_type = 'display_data';
+        output = { ...msg.content, output_type: 'display_data' };
         targets = this._displayIdMap.get(displayId);
         if (targets) {
           for (let index of targets) {

+ 5 - 1
packages/outputconsole-extension/src/index.tsx

@@ -465,7 +465,11 @@ function activateOutputLog(
           ) {
             const logger = logRegistry.getLogger(nb.context.path);
             logger.rendermime = nb.content.rendermime;
-            logger.log((msg.content as unknown) as nbformat.IOutput);
+            const output: nbformat.IOutput = {
+              ...msg.content,
+              output_type: msg.header.msg_type
+            };
+            logger.log(output);
           }
         }
       );