Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When timing metadata changes, ensure metadata.changed fires #7576

Merged
merged 4 commits into from Dec 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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