Skip to content

Commit

Permalink
chore: refine IClassicCom types (jupyter-widgets#3722)
Browse files Browse the repository at this point in the history
* chore: refine comm types
  • Loading branch information
manzt committed Mar 21, 2023
1 parent 785d159 commit c1829d3
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 28 deletions.
39 changes: 20 additions & 19 deletions packages/base/src/services-shim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

import { Kernel, KernelMessage } from '@jupyterlab/services';
import type { JSONValue, JSONObject } from '@lumino/coreutils';

/**
* Callbacks for services shim comms.
Expand Down Expand Up @@ -40,9 +41,9 @@ export interface IClassicComm {
* @return msg id
*/
open(
data: any,
callbacks: any,
metadata?: any,
data: JSONValue,
callbacks?: ICallbacks,
metadata?: JSONObject,
buffers?: ArrayBuffer[] | ArrayBufferView[]
): string;

Expand All @@ -55,9 +56,9 @@ export interface IClassicComm {
* @return message id
*/
send(
data: any,
callbacks: any,
metadata?: any,
data: JSONValue,
callbacks?: ICallbacks,
metadata?: JSONObject,
buffers?: ArrayBuffer[] | ArrayBufferView[]
): string;

Expand All @@ -70,9 +71,9 @@ export interface IClassicComm {
* @return msg id
*/
close(
data?: any,
callbacks?: any,
metadata?: any,
data?: JSONValue,
callbacks?: ICallbacks,
metadata?: JSONObject,
buffers?: ArrayBuffer[] | ArrayBufferView[]
): string;

Expand Down Expand Up @@ -218,9 +219,9 @@ export namespace shims {
* @return msg id
*/
open(
data: any,
callbacks: any,
metadata?: any,
data: JSONValue,
callbacks?: ICallbacks,
metadata?: JSONObject,
buffers?: ArrayBuffer[] | ArrayBufferView[]
): string {
const future = this.jsServicesComm.open(data, metadata, buffers);
Expand All @@ -237,9 +238,9 @@ export namespace shims {
* @return message id
*/
send(
data: any,
callbacks: any,
metadata?: any,
data: JSONValue,
callbacks?: ICallbacks,
metadata?: JSONObject,
buffers?: ArrayBuffer[] | ArrayBufferView[]
): string {
const future = this.jsServicesComm.send(data, metadata, buffers);
Expand All @@ -255,9 +256,9 @@ export namespace shims {
* @return msg id
*/
close(
data?: any,
callbacks?: any,
metadata?: any,
data?: JSONValue,
callbacks?: ICallbacks,
metadata?: JSONObject,
buffers?: ArrayBuffer[] | ArrayBufferView[]
): string {
const future = this.jsServicesComm.close(data, metadata, buffers);
Expand Down Expand Up @@ -288,7 +289,7 @@ export namespace shims {
*/
_hookupCallbacks(
future: Kernel.IShellFuture,
callbacks: ICallbacks
callbacks?: ICallbacks
): void {
if (callbacks) {
future.onReply = function (msg): void {
Expand Down
6 changes: 3 additions & 3 deletions packages/base/src/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import $ from 'jquery';

import { NativeView } from './nativeview';

import { JSONObject } from '@lumino/coreutils';
import { JSONObject, JSONValue } from '@lumino/coreutils';

import { Message, MessageLoop } from '@lumino/messaging';

Expand Down Expand Up @@ -164,8 +164,8 @@ export class WidgetModel extends Backbone.Model {
* Send a custom msg over the comm.
*/
send(
content: {},
callbacks: {},
content: JSONValue,
callbacks?: ICallbacks,
buffers?: ArrayBuffer[] | ArrayBufferView[]
): void {
if (this.comm !== undefined) {
Expand Down
17 changes: 11 additions & 6 deletions packages/controls/test/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import * as widgets from '@jupyter-widgets/base';
import * as services from '@jupyterlab/services';
import { DummyManager } from './dummy-manager';

import type { JSONValue, JSONObject } from '@lumino/coreutils';

let numComms = 0;

export class MockComm implements widgets.IClassicComm {
Expand All @@ -30,8 +32,9 @@ export class MockComm implements widgets.IClassicComm {
}

open(
data?: any,
metadata?: any,
data: JSONValue,
callbacks?: widgets.ICallbacks,
metadata?: JSONObject,
buffers?: ArrayBuffer[] | ArrayBufferView[]
): string {
if (this._on_open) {
Expand All @@ -41,8 +44,9 @@ export class MockComm implements widgets.IClassicComm {
}

close(
data?: any,
metadata?: any,
data?: JSONValue,
callbacks?: widgets.ICallbacks,
metadata?: JSONObject,
buffers?: ArrayBuffer[] | ArrayBufferView[]
): string {
if (this._on_close) {
Expand All @@ -52,8 +56,9 @@ export class MockComm implements widgets.IClassicComm {
}

send(
data?: any,
metadata?: any,
data: JSONValue,
callbacks?: widgets.ICallbacks,
metadata?: JSONObject,
buffers?: ArrayBuffer[] | ArrayBufferView[]
): string {
return '';
Expand Down

0 comments on commit c1829d3

Please sign in to comment.