Skip to content

Commit

Permalink
Update API, add change event attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
krassowski committed Aug 7, 2024
1 parent dc1f49a commit bcd3f6a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
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
13 changes: 11 additions & 2 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 @@ -752,10 +753,10 @@ export class YCodeCell
/**
* The code cell's execution state.
*/
get executionState(): 'running' | 'idle' {
get executionState(): IExecutionState {
return this.ymodel.get('execution_state') ?? 'idle';
}
set executionState(state: 'running' | 'idle') {
set executionState(state: IExecutionState) {
if (this.ymodel.get('execution_state') !== state) {
this.transact(() => {
this.ymodel.set('execution_state', state);
Expand Down Expand Up @@ -913,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

0 comments on commit bcd3f6a

Please sign in to comment.