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

Allow commands to accept partial json objects #32

Merged
merged 1 commit into from
Dec 19, 2019
Merged
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
36 changes: 18 additions & 18 deletions packages/commands/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from '@lumino/algorithm';

import {
JSONExt, ReadonlyJSONObject
JSONExt, ReadonlyPartialJSONObject
} from '@lumino/coreutils';

import {
Expand Down Expand Up @@ -168,7 +168,7 @@ class CommandRegistry {
* @returns The display label for the command, or an empty string
* if the command is not registered.
*/
label(id: string, args: ReadonlyJSONObject = JSONExt.emptyObject): string {
label(id: string, args: ReadonlyPartialJSONObject = JSONExt.emptyObject): string {
let cmd = this._commands[id];
return cmd ? cmd.label.call(undefined, args) : '';
}
Expand All @@ -183,15 +183,15 @@ class CommandRegistry {
* @returns The mnemonic index for the command, or `-1` if the
* command is not registered.
*/
mnemonic(id: string, args: ReadonlyJSONObject = JSONExt.emptyObject): number {
mnemonic(id: string, args: ReadonlyPartialJSONObject = JSONExt.emptyObject): number {
let cmd = this._commands[id];
return cmd ? cmd.mnemonic.call(undefined, args) : -1;
}

/**
* @deprecated Use `iconClass()` instead.
*/
icon(id: string, args: ReadonlyJSONObject = JSONExt.emptyObject): string {
icon(id: string, args: ReadonlyPartialJSONObject = JSONExt.emptyObject): string {
return this.iconClass(id, args);
}

Expand All @@ -205,7 +205,7 @@ class CommandRegistry {
* @returns The icon class for the command, or an empty string if
* the command is not registered.
*/
iconClass(id: string, args: ReadonlyJSONObject = JSONExt.emptyObject): string {
iconClass(id: string, args: ReadonlyPartialJSONObject = JSONExt.emptyObject): string {
let cmd = this._commands[id];
return cmd ? cmd.iconClass.call(undefined, args) : '';
}
Expand All @@ -220,7 +220,7 @@ class CommandRegistry {
* @returns The icon label for the command, or an empty string if
* the command is not registered.
*/
iconLabel(id: string, args: ReadonlyJSONObject = JSONExt.emptyObject): string {
iconLabel(id: string, args: ReadonlyPartialJSONObject = JSONExt.emptyObject): string {
let cmd = this._commands[id];
return cmd ? cmd.iconLabel.call(undefined, args) : '';
}
Expand All @@ -235,7 +235,7 @@ class CommandRegistry {
* @returns The caption for the command, or an empty string if the
* command is not registered.
*/
caption(id: string, args: ReadonlyJSONObject = JSONExt.emptyObject): string {
caption(id: string, args: ReadonlyPartialJSONObject = JSONExt.emptyObject): string {
let cmd = this._commands[id];
return cmd ? cmd.caption.call(undefined, args) : '';
}
Expand All @@ -250,7 +250,7 @@ class CommandRegistry {
* @returns The usage text for the command, or an empty string if
* the command is not registered.
*/
usage(id: string, args: ReadonlyJSONObject = JSONExt.emptyObject): string {
usage(id: string, args: ReadonlyPartialJSONObject = JSONExt.emptyObject): string {
let cmd = this._commands[id];
return cmd ? cmd.usage.call(undefined, args) : '';
}
Expand All @@ -265,7 +265,7 @@ class CommandRegistry {
* @returns The class name for the command, or an empty string if
* the command is not registered.
*/
className(id: string, args: ReadonlyJSONObject = JSONExt.emptyObject): string {
className(id: string, args: ReadonlyPartialJSONObject = JSONExt.emptyObject): string {
let cmd = this._commands[id];
return cmd ? cmd.className.call(undefined, args) : '';
}
Expand All @@ -280,7 +280,7 @@ class CommandRegistry {
* @returns The dataset for the command, or an empty dataset if
* the command is not registered.
*/
dataset(id: string, args: ReadonlyJSONObject = JSONExt.emptyObject): CommandRegistry.Dataset {
dataset(id: string, args: ReadonlyPartialJSONObject = JSONExt.emptyObject): CommandRegistry.Dataset {
let cmd = this._commands[id];
return cmd ? cmd.dataset.call(undefined, args) : {};
}
Expand All @@ -295,7 +295,7 @@ class CommandRegistry {
* @returns A boolean indicating whether the command is enabled,
* or `false` if the command is not registered.
*/
isEnabled(id: string, args: ReadonlyJSONObject = JSONExt.emptyObject): boolean {
isEnabled(id: string, args: ReadonlyPartialJSONObject = JSONExt.emptyObject): boolean {
let cmd = this._commands[id];
return cmd ? cmd.isEnabled.call(undefined, args) : false;
}
Expand All @@ -310,7 +310,7 @@ class CommandRegistry {
* @returns A boolean indicating whether the command is toggled,
* or `false` if the command is not registered.
*/
isToggled(id: string, args: ReadonlyJSONObject = JSONExt.emptyObject): boolean {
isToggled(id: string, args: ReadonlyPartialJSONObject = JSONExt.emptyObject): boolean {
let cmd = this._commands[id];
return cmd ? cmd.isToggled.call(undefined, args) : false;
}
Expand All @@ -325,7 +325,7 @@ class CommandRegistry {
* @returns A boolean indicating whether the command is visible,
* or `false` if the command is not registered.
*/
isVisible(id: string, args: ReadonlyJSONObject = JSONExt.emptyObject): boolean {
isVisible(id: string, args: ReadonlyPartialJSONObject = JSONExt.emptyObject): boolean {
let cmd = this._commands[id];
return cmd ? cmd.isVisible.call(undefined, args) : false;
}
Expand All @@ -343,7 +343,7 @@ class CommandRegistry {
* The promise will reject if the command throws an exception,
* or if the command is not registered.
*/
execute(id: string, args: ReadonlyJSONObject = JSONExt.emptyObject): Promise<any> {
execute(id: string, args: ReadonlyPartialJSONObject = JSONExt.emptyObject): Promise<any> {
// Reject if the command is not registered.
let cmd = this._commands[id];
if (!cmd) {
Expand Down Expand Up @@ -583,7 +583,7 @@ namespace CommandRegistry {
* A type alias for a user-defined command function.
*/
export
type CommandFunc<T> = (args: ReadonlyJSONObject) => T;
type CommandFunc<T> = (args: ReadonlyPartialJSONObject) => T;

/**
* A type alias for a simple immutable string dataset.
Expand Down Expand Up @@ -808,7 +808,7 @@ namespace CommandRegistry {
/**
* The arguments object passed to the command.
*/
readonly args: ReadonlyJSONObject;
readonly args: ReadonlyPartialJSONObject;

/**
* The promise which resolves with the result of the command.
Expand Down Expand Up @@ -866,7 +866,7 @@ namespace CommandRegistry {
*
* The default value is an empty object.
*/
args?: ReadonlyJSONObject;
args?: ReadonlyPartialJSONObject;

/**
* The key sequence to use when running on Windows.
Expand Down Expand Up @@ -916,7 +916,7 @@ namespace CommandRegistry {
/**
* The arguments for the command.
*/
readonly args: ReadonlyJSONObject;
readonly args: ReadonlyPartialJSONObject;
}

/**
Expand Down