kitten-cloud-function
Version:
用于编程猫源码云功能(云变量、云列表等)的客户端工具
64 lines (63 loc) • 2.15 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.KittenCloudListPushCommand = void 0;
const other_1 = require("../../../../utils/other");
const kitten_cloud_data_update_source_1 = require("../kitten-cloud-data-update-source");
const kitten_cloud_list_update_command_1 = require("./kitten-cloud-list-update-command");
class KittenCloudListPushCommand extends kitten_cloud_list_update_command_1.KittenCloudListUpdateCommand {
constructor(source, list, value) {
super(source, list);
this.list = list;
this.value = value;
this.effective = other_1.None;
}
execute() {
if (this.effective != other_1.None) {
throw new Error("无法执行命令:命令已被执行,不能重复执行");
}
this.effective = this.list.length < this.list.listLengthLimit.value;
if (this.effective) {
this.list.value.push(this.value);
this.list.pushed.emit({
source: this.source,
item: this.value
});
}
}
revoke() {
if (this.effective == other_1.None) {
throw new Error("无法撤销命令:命令尚未执行");
}
if (this.effective) {
this.list.value.pop();
this.list.popped.emit({
source: kitten_cloud_data_update_source_1.KittenCloudDataUpdateSource.REVOKE,
item: this.value
});
}
this.effective = other_1.None;
}
isEffective() {
return this.effective == other_1.None ? this.list.length < this.list.listLengthLimit.value : this.effective;
}
isLegal() {
return true;
}
toJSON() {
return {
method: "push",
value: this.value
};
}
toCloudJSON() {
return {
action: "append",
cvid: this.list.cvid,
value: this.value
};
}
toString() {
return `添加 ${JSON.stringify(this.value)} 到云列表 ${this.data.name} 末项`;
}
}
exports.KittenCloudListPushCommand = KittenCloudListPushCommand;