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