Skip to content

Commit

Permalink
Merge pull request #7576 from mlucool/timing-metadata-fix
Browse files Browse the repository at this point in the history
When timing metadata changes, ensure metadata.changed fires
  • Loading branch information
saulshanabrook committed Dec 4, 2019
2 parents bfd967d + 92a24ad commit a445a8c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
11 changes: 11 additions & 0 deletions packages/cells/src/model.ts
Expand Up @@ -101,6 +101,11 @@ export interface ICodeCellModel extends ICellModel {
* The cell outputs.
*/
readonly outputs: IOutputAreaModel;

/**
* Clear execution, outputs, and related metadata
*/
clearExecution(): void;
}

/**
Expand Down Expand Up @@ -521,6 +526,12 @@ export class CodeCellModel extends CellModel implements ICodeCellModel {
this.modelDB.setValue('executionCount', newValue || null);
}

clearExecution() {
this.outputs.clear();
this.executionCount = null;
this.metadata.delete('execution');
}

/**
* The cell outputs.
*/
Expand Down
15 changes: 10 additions & 5 deletions packages/cells/src/widget.ts
Expand Up @@ -1037,8 +1037,7 @@ export namespace CodeCell {
let model = cell.model;
let code = model.value.text;
if (!code.trim() || !session.kernel) {
model.executionCount = null;
model.outputs.clear();
model.clearExecution();
return;
}
let cellId = { cellId: model.id };
Expand All @@ -1048,7 +1047,7 @@ export namespace CodeCell {
...cellId
};
const { recordTiming } = metadata;
model.executionCount = null;
model.clearExecution();
cell.outputHidden = false;
cell.setPrompt('*');
model.trusted = true;
Expand Down Expand Up @@ -1083,7 +1082,10 @@ export namespace CodeCell {
if (!value) {
return;
}
const timingInfo: any = model.metadata.get('execution') || {};
const timingInfo: any = Object.assign(
{},
model.metadata.get('execution')
);
timingInfo[`iopub.${label}`] = value;
model.metadata.set('execution', timingInfo);
return true;
Expand All @@ -1096,7 +1098,10 @@ export namespace CodeCell {
model.executionCount = msg.content.execution_count;
const started = msg.metadata.started as string;
if (recordTiming && started) {
const timingInfo = (model.metadata.get('execution') as any) || {};
const timingInfo = Object.assign(
{},
model.metadata.get('execution') as any
);
if (started) {
timingInfo['shell.execute_reply.started'] = started;
}
Expand Down
8 changes: 3 additions & 5 deletions packages/notebook/src/actions.tsx
Expand Up @@ -1053,9 +1053,8 @@ export namespace NotebookActions {
const child = notebook.widgets[index];

if (notebook.isSelectedOrActive(child) && cell.type === 'code') {
cell.outputs.clear();
cell.clearExecution();
(child as CodeCell).outputHidden = false;
cell.executionCount = null;
}
});
Private.handleState(notebook, state);
Expand All @@ -1080,8 +1079,7 @@ export namespace NotebookActions {
const child = notebook.widgets[index];

if (cell.type === 'code') {
cell.outputs.clear();
cell.executionCount = null;
cell.clearExecution();
(child as CodeCell).outputHidden = false;
}
});
Expand Down Expand Up @@ -1605,7 +1603,7 @@ namespace Private {
return ran;
});
}
(cell.model as ICodeCellModel).executionCount = null;
(cell.model as ICodeCellModel).clearExecution();
break;
default:
break;
Expand Down

0 comments on commit a445a8c

Please sign in to comment.