Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

phosphor-command

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

phosphor-command - npm Package Compare versions

Comparing version 0.3.0 to 0.4.0

163

lib/index.d.ts

@@ -8,10 +8,9 @@ import { IDisposable } from 'phosphor-disposable';

/**
* A signal emitted when the command's [[canExecute]] state changes.
* A signal emitted when the command's state changes.
*
* #### Notes
* Consumers of the command can subscribe to this signal in order to
* know when to re-query for the current executable state and update
* their visual representations accordingly.
* update their visual representation of the command when it changes.
*/
canExecuteChanged: ISignal<ICommand, void>;
changed: ISignal<ICommand, void>;
/**

@@ -25,20 +24,25 @@ * A unique identifier for the command.

/**
* Test whether the command can execute in its current state.
* Test whether the command is enabled.
*
* @param args - The proposed arguments for the command. These should
* be simple JSON types. If the command does not require arguments,
* this may be `null`.
* @returns `true` if the command is enabled, `false` otherwise.
*
* @returns `true` if the command can execute with the given args,
* `false` otherwise.
* #### Notes
* The [[changed]] signal should be emitted if the return value
* changes at runtime.
*/
isEnabled(): boolean;
/**
* Test whether the command is checked.
*
* @returns `true` if the command is checked, `false` otherwise.
*
* #### Notes
* When the potential result of this method changes at runtime, the
* [[canExecuteChanged]] signal should be emitted.
* The [[changed]] signal should be emitted if the return value
* changes at runtime.
*/
canExecute(args: any): boolean;
isChecked(): boolean;
/**
* Execute the command with the specified arguments.
*
* @param args - The arguments for the command. These should be
* @param args - The arguments for the command. The args should be
* simple JSON types. If the command does not require arguments,

@@ -48,3 +52,3 @@ * this may be `null`.

* #### Notes
* Calling `execute` when `canExecute` returns `false` will result
* Calling `execute` when `isEnabled` returns `false` will result
* in undefined behavior.

@@ -55,35 +59,26 @@ */

/**
* A concrete implementation of [[ICommand]].
*
* A `DelegateCommand` wraps a pair of functions to facilitate the easy
* creation of commands without requiring subclassing or boilerplate.
* An abstract base class for implementing concrete commands.
*/
export declare class DelegateCommand implements ICommand {
export declare abstract class Command implements ICommand {
/**
* A signal emitted when the command's [[canExecute]] state changes.
* A signal emitted when the command's state changes.
*
* **See also:** [[canExecuteChanged]]
* **See also:** [[changed]]
*/
static canExecuteChangedSignal: Signal<DelegateCommand, void>;
static changedSignal: Signal<Command, void>;
/**
* Construct a new delegate command.
* Construct a new command.
*
* @param id - The identifier for the command.
*
* @param execute - The function which executes the command logic.
*
* @param canExecute - An optional function which determines whether
* the command can execute in its current state.
*/
constructor(id: string, execute: (args: any) => void, canExecute?: (args: any) => boolean);
constructor(id: string);
/**
* A signal emitted when the command's [[canExecute]] state changes.
* A signal emitted when the command's state changes.
*
* #### Notes
* This is emitted automatically when the [[enabled]] state changes.
* This should be emitted by a subclass as necessary.
*
* This can be emitted manually by the creator of the command when
* the result of the `canExecute` delegate function changes.
* This is a pure delegate to the [[changedSignal]].
*/
canExecuteChanged: ISignal<DelegateCommand, void>;
changed: ISignal<Command, void>;
/**

@@ -93,6 +88,61 @@ * Get the identifier for the command.

* #### Notes
* This is a read-only property.
* This is a read-only constant property.
*/
id: string;
/**
* Test whether the command is enabled.
*
* @returns `true` if the command is enabled, `false` otherwise.
*
* #### Notes
* A subclass may reimplement this method as needed. If the state
* changes at runtime, the [[changed]] signal should be emitted.
*
* The default implementation of this method returns `true`.
*/
isEnabled(): boolean;
/**
* Test whether the command is checked.
*
* @returns `true` if the command is checked, `false` otherwise.
*
* #### Notes
* A subclass may reimplement this method as needed. If the state
* changes at runtime, the [[changed]] signal should be emitted.
*
* The default implementation of this method returns `false`.
*/
isChecked(): boolean;
/**
* Execute the command with the specified arguments.
*
* @param args - The arguments for the command. The args should be
* simple JSON types. If the command does not require arguments,
* this may be `null`.
*
* #### Notes
* Calling `execute` when `isEnabled` returns `false` will result
* in undefined behavior.
*
* This abstract method must be implemented by a subclass.
*/
abstract execute(args: any): void;
private _id;
}
/**
* A concrete implementation of [[ICommand]].
*
* A `DelegateCommand` wraps a function to facilitate the creation of
* simple commands without requiring subclassing or extra boilerplate.
*/
export declare class DelegateCommand extends Command {
/**
* Construct a new delegate command.
*
* @param id - The identifier for the command.
*
* @param execute - The function which executes the command logic.
*/
constructor(id: string, execute: (args: any) => void);
/**
* Get the enabled state of the delegate command.

@@ -104,25 +154,37 @@ */

* #### Notes
* This will emit the [[canExecuteChanged]] if the state changes.
* This will emit the [[changed]] signal if the state changes.
*/
enabled: boolean;
/**
* Test whether the command can execute in its current state.
* Get the checked state of the delegate command.
*/
/**
* Set the checked state of the delegate command.
*
* @param args - The proposed arguments for the command. These should
* be simple JSON types. If the command does not require arguments,
* this may be `null`.
* #### Notes
* This will emit the [[changed]] signal if the state changes.
*/
checked: boolean;
/**
* Test whether the command is enabled.
*
* @returns `true` if the command can execute with the given args,
* `false` otherwise.
* @returns `true` if the command is enabled, `false` otherwise.
*
* #### Notes
* If the [[enabled]] flag is set to `false`, this method will always
* return `false`. If a `canExecute` function is provided, the result
* of that function will be returned. Otherwise, this returns `true`.
* This returns the command's [[enabled]] state.
*/
canExecute(args: any): boolean;
isEnabled(): boolean;
/**
* Test whether the command is checked.
*
* @returns `true` if the command is checked, `false` otherwise.
*
* #### Notes
* This returns the command's [[checked]] state.
*/
isChecked(): boolean;
/**
* Execute the command with the specified arguments.
*
* @param args - The arguments for the command. These should be
* @param args - The arguments for the command. The args should be
* simple JSON types. If the command does not require arguments,

@@ -132,10 +194,9 @@ * this may be `null`.

* #### Notes
* Calling `execute` when `canExecute` returns `false` will result
* Calling `execute` when `isEnabled` returns `false` will result
* in undefined behavior.
*/
execute(args: any): void;
private _id;
private _enabled;
private _checked;
private _execute;
private _canExecute;
}

@@ -142,0 +203,0 @@ /**

@@ -9,39 +9,32 @@ /*-----------------------------------------------------------------------------

'use strict';
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var phosphor_disposable_1 = require('phosphor-disposable');
var phosphor_signaling_1 = require('phosphor-signaling');
/**
* A concrete implementation of [[ICommand]].
*
* A `DelegateCommand` wraps a pair of functions to facilitate the easy
* creation of commands without requiring subclassing or boilerplate.
* An abstract base class for implementing concrete commands.
*/
var DelegateCommand = (function () {
var Command = (function () {
/**
* Construct a new delegate command.
* Construct a new command.
*
* @param id - The identifier for the command.
*
* @param execute - The function which executes the command logic.
*
* @param canExecute - An optional function which determines whether
* the command can execute in its current state.
*/
function DelegateCommand(id, execute, canExecute) {
this._enabled = true;
function Command(id) {
this._id = id;
this._execute = execute;
this._canExecute = canExecute || null;
}
Object.defineProperty(DelegateCommand.prototype, "canExecuteChanged", {
Object.defineProperty(Command.prototype, "changed", {
/**
* A signal emitted when the command's [[canExecute]] state changes.
* A signal emitted when the command's state changes.
*
* #### Notes
* This is emitted automatically when the [[enabled]] state changes.
* This should be emitted by a subclass as necessary.
*
* This can be emitted manually by the creator of the command when
* the result of the `canExecute` delegate function changes.
* This is a pure delegate to the [[changedSignal]].
*/
get: function () {
return DelegateCommand.canExecuteChangedSignal.bind(this);
return Command.changedSignal.bind(this);
},

@@ -51,3 +44,3 @@ enumerable: true,

});
Object.defineProperty(DelegateCommand.prototype, "id", {
Object.defineProperty(Command.prototype, "id", {
/**

@@ -57,3 +50,3 @@ * Get the identifier for the command.

* #### Notes
* This is a read-only property.
* This is a read-only constant property.
*/

@@ -66,2 +59,60 @@ get: function () {

});
/**
* Test whether the command is enabled.
*
* @returns `true` if the command is enabled, `false` otherwise.
*
* #### Notes
* A subclass may reimplement this method as needed. If the state
* changes at runtime, the [[changed]] signal should be emitted.
*
* The default implementation of this method returns `true`.
*/
Command.prototype.isEnabled = function () {
return true;
};
/**
* Test whether the command is checked.
*
* @returns `true` if the command is checked, `false` otherwise.
*
* #### Notes
* A subclass may reimplement this method as needed. If the state
* changes at runtime, the [[changed]] signal should be emitted.
*
* The default implementation of this method returns `false`.
*/
Command.prototype.isChecked = function () {
return false;
};
/**
* A signal emitted when the command's state changes.
*
* **See also:** [[changed]]
*/
Command.changedSignal = new phosphor_signaling_1.Signal();
return Command;
})();
exports.Command = Command;
/**
* A concrete implementation of [[ICommand]].
*
* A `DelegateCommand` wraps a function to facilitate the creation of
* simple commands without requiring subclassing or extra boilerplate.
*/
var DelegateCommand = (function (_super) {
__extends(DelegateCommand, _super);
/**
* Construct a new delegate command.
*
* @param id - The identifier for the command.
*
* @param execute - The function which executes the command logic.
*/
function DelegateCommand(id, execute) {
_super.call(this, id);
this._enabled = true;
this._checked = false;
this._execute = execute;
}
Object.defineProperty(DelegateCommand.prototype, "enabled", {

@@ -78,3 +129,3 @@ /**

* #### Notes
* This will emit the [[canExecuteChanged]] if the state changes.
* This will emit the [[changed]] signal if the state changes.
*/

@@ -86,3 +137,3 @@ set: function (value) {

this._enabled = value;
this.canExecuteChanged.emit(void 0);
this.changed.emit(void 0);
},

@@ -92,27 +143,51 @@ enumerable: true,

});
Object.defineProperty(DelegateCommand.prototype, "checked", {
/**
* Get the checked state of the delegate command.
*/
get: function () {
return this._checked;
},
/**
* Set the checked state of the delegate command.
*
* #### Notes
* This will emit the [[changed]] signal if the state changes.
*/
set: function (value) {
if (this._checked === value) {
return;
}
this._checked = value;
this.changed.emit(void 0);
},
enumerable: true,
configurable: true
});
/**
* Test whether the command can execute in its current state.
* Test whether the command is enabled.
*
* @param args - The proposed arguments for the command. These should
* be simple JSON types. If the command does not require arguments,
* this may be `null`.
* @returns `true` if the command is enabled, `false` otherwise.
*
* @returns `true` if the command can execute with the given args,
* `false` otherwise.
*
* #### Notes
* If the [[enabled]] flag is set to `false`, this method will always
* return `false`. If a `canExecute` function is provided, the result
* of that function will be returned. Otherwise, this returns `true`.
* This returns the command's [[enabled]] state.
*/
DelegateCommand.prototype.canExecute = function (args) {
if (this._enabled && this._canExecute) {
return this._canExecute.call(void 0, args);
}
DelegateCommand.prototype.isEnabled = function () {
return this._enabled;
};
/**
* Test whether the command is checked.
*
* @returns `true` if the command is checked, `false` otherwise.
*
* #### Notes
* This returns the command's [[checked]] state.
*/
DelegateCommand.prototype.isChecked = function () {
return this._checked;
};
/**
* Execute the command with the specified arguments.
*
* @param args - The arguments for the command. These should be
* @param args - The arguments for the command. The args should be
* simple JSON types. If the command does not require arguments,

@@ -122,3 +197,3 @@ * this may be `null`.

* #### Notes
* Calling `execute` when `canExecute` returns `false` will result
* Calling `execute` when `isEnabled` returns `false` will result
* in undefined behavior.

@@ -129,10 +204,4 @@ */

};
/**
* A signal emitted when the command's [[canExecute]] state changes.
*
* **See also:** [[canExecuteChanged]]
*/
DelegateCommand.canExecuteChangedSignal = new phosphor_signaling_1.Signal();
return DelegateCommand;
})();
})(Command);
exports.DelegateCommand = DelegateCommand;

@@ -139,0 +208,0 @@ /**

{
"name": "phosphor-command",
"version": "0.3.0",
"version": "0.4.0",
"description": "A module for expressing the command pattern.",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc