Explorar el Código

complete refactor of cells to use IOptions pattern instead of static methods

A. Darian hace 9 años
padre
commit
d8d7b2bfb7
Se han modificado 2 ficheros con 9 adiciones y 6 borrados
  1. 1 1
      src/console/widget.ts
  2. 8 5
      src/notebook/cells/widget.ts

+ 1 - 1
src/console/widget.ts

@@ -199,7 +199,7 @@ class ConsoleWidget extends Widget {
    */
   static createPrompt(rendermime: RenderMime<Widget>): CodeCellWidget {
     let model = new CodeCellModel();
-    return new CodeCellWidget(model, rendermime);
+    return new CodeCellWidget({ model, rendermime });
   }
 
   /**

+ 8 - 5
src/notebook/cells/widget.ts

@@ -415,7 +415,7 @@ class CodeCellWidget extends BaseCellWidget {
   }
 
   /**
-   * Handle if the widget receives a new model.
+   * Handle the widget receiving a new model.
    */
   protected onModelChanged(sender: BaseCellWidget, args: IChangedArgs<ICellModel>): void {
     if (args.oldValue) {
@@ -425,12 +425,15 @@ class CodeCellWidget extends BaseCellWidget {
     let factory = this._factory;
     let model = args.newValue as ICodeCellModel;
 
+    if (this._output) {
+      this._output.dispose();
+    }
     this._output = factory.createOutputArea(model.outputs, this._rendermime);
     this._output.trusted = this.trusted;
     (this.layout as PanelLayout).addChild(this._output);
     this._collapsedCursor = model.getMetadata('collapsed');
     this._scrolledCursor = model.getMetadata('scrolled');
-    this.setPrompt(String(model.executionCount));
+    this.setPrompt(`${model.executionCount}`);
     model.stateChanged.connect(this.onModelStateChanged, this);
   }
 
@@ -440,7 +443,7 @@ class CodeCellWidget extends BaseCellWidget {
   protected onModelStateChanged(model: ICodeCellModel, args: IChangedArgs<any>): void {
     switch (args.name) {
     case 'executionCount':
-      this.setPrompt(String(model.executionCount));
+      this.setPrompt(`${model.executionCount}`);
       break;
     default:
       break;
@@ -634,8 +637,8 @@ class RawCellWidget extends BaseCellWidget {
   /**
    * Construct a raw cell widget.
    */
-  constructor(model: ICellModel) {
-    super(model);
+  constructor(options: BaseCellWidget.IOptions) {
+    super(options);
     this.addClass(RAW_CELL_CLASS);
   }
 }