kitten-cloud-function
Version:
用于编程猫源码云功能(云变量、云列表等)的客户端工具
72 lines (71 loc) • 2.39 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.KittenCloudListUnshiftCommand = 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 KittenCloudListUnshiftCommand extends kitten_cloud_list_update_command_1.KittenCloudListUpdateCommand {
constructor(source, list, value) {
super(source, list);
this.list = list;
this.value = value;
this.overflow = other_1.None;
this.overflowValue = 0;
}
execute() {
if (this.overflow != other_1.None) {
throw new Error("无法执行命令:命令已被执行,不能重复执行");
}
this.list.value.unshift(this.value);
this.overflow = this.list.length > this.list.listLengthLimit.value;
if (this.overflow) {
this.overflowValue = this.list.value.pop();
}
this.list.unshifted.emit({
source: this.source,
item: this.value
});
}
revoke() {
if (this.overflow == other_1.None) {
throw new Error("无法撤销命令:命令尚未执行");
}
this.list.value.shift();
this.overflow = other_1.None;
this.list.removed.emit({
source: kitten_cloud_data_update_source_1.KittenCloudDataUpdateSource.REVOKE,
index: 0,
item: this.overflowValue
});
if (this.overflow) {
this.list.value.push(this.overflowValue);
this.list.pushed.emit({
source: kitten_cloud_data_update_source_1.KittenCloudDataUpdateSource.REVOKE,
item: this.overflowValue
});
}
}
isEffective() {
return true;
}
isLegal() {
return true;
}
toJSON() {
return {
method: "unshift",
value: this.value
};
}
toCloudJSON() {
return {
action: "unshift",
cvid: this.list.cvid,
value: this.value
};
}
toString() {
return `添加 ${JSON.stringify(this.value)} 到云列表 ${this.data.name} 首项`;
}
}
exports.KittenCloudListUnshiftCommand = KittenCloudListUnshiftCommand;