kitten-cloud-function
Version:
用于编程猫源码云功能(云变量、云列表等)的客户端工具
60 lines (59 loc) • 2.17 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.KittenCloudVariableSetCommand = void 0;
const other_1 = require("../../../../utils/other");
const kitten_cloud_data_update_source_1 = require("../kitten-cloud-data-update-source");
const kitten_cloud_variable_update_command_1 = require("./kitten-cloud-variable-update-command");
class KittenCloudVariableSetCommand extends kitten_cloud_variable_update_command_1.KittenCloudVariableUpdateCommand {
constructor(source, variable, value) {
super(source, variable);
this.value = value;
this.backup = other_1.None;
}
execute() {
if (this.backup != other_1.None) {
throw new Error(`无法执行命令:命令已被执行,不能重复执行`);
}
this.backup = this.variable.value;
this.variable.value = this.value;
this.variable.changed.emit({
source: this.source,
originalValue: this.backup,
newValue: this.value
});
}
revoke() {
if (this.backup == other_1.None) {
throw new Error(`无法撤销命令:命令尚未执行`);
}
this.variable.value = this.backup;
this.variable.changed.emit({
source: kitten_cloud_data_update_source_1.KittenCloudDataUpdateSource.REVOKE,
originalValue: this.value,
newValue: this.backup
});
this.backup = other_1.None;
}
isEffective() {
return this.backup == other_1.None ? this.value !== this.variable.value : this.value !== this.backup;
}
toJSON() {
return {
method: "set",
value: this.value
};
}
isLegal() {
return true;
}
merge(that) {
if ((this.backup == other_1.None) != (that.backup == other_1.None)) {
throw new Error("命令执行状态不一致,不能合并");
}
this.value = that.value;
}
toString() {
return `设置云变量 ${this.data.name} 的值为 ${JSON.stringify(this.value)} `;
}
}
exports.KittenCloudVariableSetCommand = KittenCloudVariableSetCommand;