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

Expose execution_state in the JS package #259

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions javascript/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,8 @@ export interface ISharedBaseCell<
toJSON(): nbformat.IBaseCell;
}

export type IExecutionState = 'running' | 'idle';

/**
* Implements an API for nbformat.ICodeCell.
*/
Expand All @@ -509,6 +511,11 @@ export interface ISharedCodeCell
*/
execution_count: nbformat.ExecutionCount;

/**
* The code cell's execution state.
*/
executionState: IExecutionState;

/**
* Cell outputs
*/
Expand Down Expand Up @@ -746,6 +753,13 @@ export type CellChange = SourceChange & {
oldValue?: number;
newValue?: number;
};
/**
* Cell execution state change
*/
executionStateChange?: {
oldValue?: IExecutionState;
newValue?: IExecutionState;
};
/**
* Cell metadata change
*/
Expand Down
23 changes: 23 additions & 0 deletions javascript/src/ycell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Awareness } from 'y-protocols/awareness';
import * as Y from 'yjs';
import type {
CellChange,
IExecutionState,
IMapChange,
ISharedAttachmentsCell,
ISharedBaseCell,
Expand Down Expand Up @@ -749,6 +750,20 @@ export class YCodeCell
}
}

/**
* The code cell's execution state.
*/
get executionState(): IExecutionState {
return this.ymodel.get('execution_state') ?? 'idle';
}
set executionState(state: IExecutionState) {
if (this.ymodel.get('execution_state') !== state) {
this.transact(() => {
this.ymodel.set('execution_state', state);
}, false);
}
}

/**
* Cell outputs.
*/
Expand Down Expand Up @@ -899,6 +914,14 @@ export class YCodeCell
};
}

if (modelEvent && modelEvent.keysChanged.has('execution_state')) {
const change = modelEvent.changes.keys.get('execution_state');
changes.executionStateChange = {
oldValue: change!.oldValue,
newValue: this.ymodel.get('execution_state')
};
}

return changes;
}

Expand Down
Loading