Explorar o código

Do outputs_hidden to collapsed conversion only at initial cell model construction.

Perhaps we should even move it earlier in the chain when the notebook model is read.
Jason Grout %!s(int64=6) %!d(string=hai) anos
pai
achega
cca4659c4d
Modificáronse 2 ficheiros con 18 adicións e 21 borrados
  1. 6 14
      packages/cells/src/model.ts
  2. 12 7
      tests/test-cells/src/model.spec.ts

+ 6 - 14
packages/cells/src/model.ts

@@ -3,7 +3,7 @@
 | Distributed under the terms of the Modified BSD License.
 | Distributed under the terms of the Modified BSD License.
 |----------------------------------------------------------------------------*/
 |----------------------------------------------------------------------------*/
 
 
-import { JSONExt, JSONObject, JSONValue} from '@phosphor/coreutils';
+import { JSONExt, JSONObject, JSONValue } from '@phosphor/coreutils';
 
 
 import { ISignal, Signal } from '@phosphor/signaling';
 import { ISignal, Signal } from '@phosphor/signaling';
 
 
@@ -495,20 +495,12 @@ export class CodeCellModel extends CellModel implements ICodeCellModel {
 
 
     // We prefer output collapse status to be in the `collapse` metadata field
     // We prefer output collapse status to be in the `collapse` metadata field
     // rather than the `jupyter.outputs_hidden` field for backwards
     // rather than the `jupyter.outputs_hidden` field for backwards
-    // compatibility. See https://github.com/jupyter/nbformat/issues/137.
+    // compatibility. We only do this conversion at construction, so See https://github.com/jupyter/nbformat/issues/137.
+
+    // We only do this conversion at construction so that we can understand
+    // nbformat 4.4. We don't do the conversion at runtime so the behavior is
+    // not confusing.
     this._convertCollapsed();
     this._convertCollapsed();
-    this.metadata.changed.connect(
-      (_, args) => {
-        if (
-          args.key === 'jupyter' &&
-          args.newValue &&
-          args.newValue.hasOwnProperty('outputs_hidden')
-        ) {
-          this._convertCollapsed();
-        }
-      },
-      this
-    );
   }
   }
 
 
   /**
   /**

+ 12 - 7
tests/test-cells/src/model.spec.ts

@@ -448,9 +448,8 @@ describe('cells/model', () => {
     });
     });
 
 
     describe('.metadata', () => {
     describe('.metadata', () => {
-      it('should consolidate collapsed and jupyter.outputs_hidden metadata when changed', () => {
+      it('should not consolidate collapsed and jupyter.outputs_hidden metadata when changed', () => {
         const metadata = new CodeCellModel({}).metadata;
         const metadata = new CodeCellModel({}).metadata;
-        let jupyter: JSONObject | undefined;
 
 
         expect(metadata.get('collapsed')).to.be.undefined;
         expect(metadata.get('collapsed')).to.be.undefined;
         expect(metadata.get('jupyter')).to.be.undefined;
         expect(metadata.get('jupyter')).to.be.undefined;
@@ -459,20 +458,26 @@ describe('cells/model', () => {
         metadata.set('collapsed', true);
         metadata.set('collapsed', true);
         metadata.set('jupyter', { outputs_hidden: false });
         metadata.set('jupyter', { outputs_hidden: false });
         expect(metadata.get('collapsed')).to.be.true;
         expect(metadata.get('collapsed')).to.be.true;
-        expect(metadata.get('jupyter')).to.be.undefined;
+        expect(metadata.get('jupyter')).to.deep.equal({
+          outputs_hidden: false
+        });
 
 
         // default values are not set
         // default values are not set
         metadata.delete('collapsed');
         metadata.delete('collapsed');
         metadata.set('jupyter', { outputs_hidden: false });
         metadata.set('jupyter', { outputs_hidden: false });
         expect(metadata.get('collapsed')).to.be.undefined;
         expect(metadata.get('collapsed')).to.be.undefined;
-        expect(metadata.get('jupyter')).to.be.undefined;
+        expect(metadata.get('jupyter')).to.deep.equal({
+          outputs_hidden: false
+        });
 
 
         // other jupyter values are not disturbed
         // other jupyter values are not disturbed
         metadata.delete('collapsed');
         metadata.delete('collapsed');
         metadata.set('jupyter', { outputs_hidden: true, other: true });
         metadata.set('jupyter', { outputs_hidden: true, other: true });
-        expect(metadata.get('collapsed')).to.be.true;
-        jupyter = metadata.get('jupyter') as JSONObject;
-        expect(jupyter.outputs_hidden).to.be.undefined;
+        expect(metadata.get('collapsed')).to.be.undefined;
+        expect(metadata.get('jupyter')).to.deep.equal({
+          other: true,
+          outputs_hidden: false
+        });
       });
       });
     });
     });