projects/wms-framework/src/lib/regionsframework/commands/SimpleDelegateCommand.ts
Represents a command which must be executed without parameters.
Properties |
|
Methods |
Accessors |
constructor(f: () => void, canExecute?: () => void)
|
Creates an instance of SimpleDelegateCommand. |
CanExecuteChanged |
Type : SubscriptionEvent<any>
|
Default value : new SubscriptionEvent()
|
Event trigerred when |
Private isActive |
Default value : true
|
Stored the value of |
IsActiveChanged |
Type : SubscriptionEvent<any>
|
Default value : new SubscriptionEvent()
|
Event triguerred when |
CanExecute |
CanExecute()
|
Query if the command can be executed.
Returns :
boolean
{boolean} |
Execute |
Execute()
|
Executes the command if it can be executed.
Returns :
void
|
RaiseCanExecuteChanged |
RaiseCanExecuteChanged()
|
Alerts that
Returns :
void
|
IsActive | ||||||
getIsActive()
|
||||||
The active status of the command.
Returns :
boolean
|
||||||
setIsActive(value: boolean)
|
||||||
Parameters :
Returns :
void
|
import { ICommand } from '../../baseframework/ICommand';
import { SubscriptionEvent } from '../../utils/SubscriptionEvent';
/**
* Represents a command which must be executed without parameters.
*
* @export
* @class SimpleDelegateCommand
* @implements {ICommand}
* @wType Microsoft.Practices.Prism.Commands.DelegateCommand
*/
export class SimpleDelegateCommand implements ICommand {
/**
* Event trigerred when `CanExecute` changes its value.
*
* @type {SubscriptionEvent<any>}
* @memberof SimpleDelegateCommand
*/
CanExecuteChanged: SubscriptionEvent<any> = new SubscriptionEvent();
/**
* Event triguerred when `IsActive` changes its value.
*
* @type {SubscriptionEvent<any>}
* @memberof SimpleDelegateCommand
*/
IsActiveChanged: SubscriptionEvent<any> = new SubscriptionEvent();
/**
* Stored the value of `IsActive`.
*
* @private
* @memberof SimpleDelegateCommand
*/
private isActive = true;
/**
* Creates an instance of SimpleDelegateCommand.
*
* @param {() => void} f The function to call when the command is executed.
* @param {(() => boolean)} [canExecute] The function to determine if the command can be executed.
* @memberof SimpleDelegateCommand
*/
constructor(private f: () => void, private canExecute?: () => boolean) {}
/**
* The active status of the command.
*
* @type {boolean}
* @memberof SimpleDelegateCommand
*/
get IsActive(): boolean {
return this.isActive;
}
set IsActive(value: boolean) {
if (this.isActive !== value) {
this.isActive = value;
this.IsActiveChanged.fire([this, {}]);
}
}
/**
* Query if the command can be executed.
*
* @return {*} {boolean}
* @memberof SimpleDelegateCommand
*/
CanExecute(): boolean {
return this.canExecute?.() ?? true;
}
/**
* Executes the command if it can be executed.
*
* @memberof SimpleDelegateCommand
*/
Execute(): void {
if (this.CanExecute()) {
this.f();
}
}
/**
* Alerts that `CanExecute()` has changed its value.
*
* @memberof SimpleDelegateCommand
*/
RaiseCanExecuteChanged() {
this.CanExecuteChanged?.fire([]);
}
}