Skip to content

Commit

Permalink
vscode-notebook-renderer: update to separate preload type
Browse files Browse the repository at this point in the history
  • Loading branch information
connor4312 committed May 4, 2021
1 parent 8f0346c commit efdcae4
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 28 deletions.
1 change: 1 addition & 0 deletions types/vscode-notebook-renderer/OTHER_FILES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
preload.d.ts
7 changes: 7 additions & 0 deletions types/vscode-notebook-renderer/events.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export interface Disposable {
dispose(): void;
}

export interface VSCodeEvent<T> {
(listener: (e: T) => any, thisArgs?: any, disposables?: Disposable[]): Disposable;
}
23 changes: 2 additions & 21 deletions types/vscode-notebook-renderer/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,9 @@
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// Minimum TypeScript Version: 3.0

// todo: update "Project" link above to docs site, once it becomes available
import { VSCodeEvent } from './events';

export interface Disposable {
dispose(): void;
}

export interface VSCodeEvent<T> {
(listener: (e: T) => any, thisArgs?: any, disposables?: Disposable[]): Disposable;
}
export * from './events';

/**
* Notebook output event -- a supertype of the `NotebookCellOutputItem` in the VS Code types.
Expand All @@ -29,13 +23,6 @@ export interface NotebookOutputEventParams {
export interface NotebookRendererApi<T> {
setState(value: T): void;
getState(): T | undefined;

/**
* Sends a message to the renderer extension code. Can be received in
* the `onDidReceiveMessage` event in `NotebookCommunication`.
*/
postMessage(msg: unknown): void;

/**
* Fired before an output is destroyed, with its output ID, or undefined if
* all cells are about to unmount.
Expand All @@ -48,12 +35,6 @@ export interface NotebookRendererApi<T> {
* API, and `onWillDestroyOutput`.
*/
onDidCreateOutput: VSCodeEvent<NotebookOutputEventParams>;

/**
* Called when the renderer uses `postMessage` on the NotebookCommunication
* instance for this renderer.
*/
onDidReceiveMessage: VSCodeEvent<any>;
}

declare global {
Expand Down
6 changes: 6 additions & 0 deletions types/vscode-notebook-renderer/preload.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { VSCodeEvent } from './events';

declare global {
const onDidReceiveKernelMessage: VSCodeEvent<any>;
function postKernelMessage(data: unknown): void;
}
16 changes: 9 additions & 7 deletions types/vscode-notebook-renderer/vscode-notebook-renderer-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@ const listener = notebookApi.onDidCreateOutput(({ element, outputId, value, mime

listener.dispose();

notebookApi.onDidReceiveMessage(msg => {
// $ExpectType any
msg;

notebookApi.postMessage(msg);
});

notebookApi.onWillDestroyOutput(evt => {
// $ExpectType { outputId: string; } | undefined
evt;
});

import 'vscode-notebook-renderer/preload';

onDidReceiveKernelMessage(msg => {
// $ExpectType any
msg;

postKernelMessage(msg);
});

0 comments on commit efdcae4

Please sign in to comment.