kitten-cloud-function
Version:
用于编程猫源码云功能(云变量、云列表等)的客户端工具
58 lines (57 loc) • 1.69 kB
JavaScript
import { None } from "../../../../utils/other";
import { KittenCloudDataUpdateSource } from "../kitten-cloud-data-update-source";
import { KittenCloudListUpdateCommand } from "./kitten-cloud-list-update-command";
export class KittenCloudListPopCommand extends KittenCloudListUpdateCommand {
constructor(source, list) {
super(source, list);
this.list = list;
this.effective = None;
this.backup = 0;
}
execute() {
if (this.effective != None) {
throw new Error("无法执行命令:命令已被执行,不能重复执行");
}
this.effective = this.list.length > 0;
if (this.effective) {
this.backup = this.list.value.pop();
this.list.popped.emit({
source: this.source,
item: this.backup
});
}
}
revoke() {
if (this.effective == None) {
throw new Error("无法撤销命令:命令尚未执行");
}
if (this.effective) {
this.list.value.push(this.backup);
this.list.pushed.emit({
source: KittenCloudDataUpdateSource.REVOKE,
item: this.backup
});
}
this.effective = None;
}
isEffective() {
return this.effective == None ? this.list.length > 0 : this.effective;
}
isLegal() {
return true;
}
toJSON() {
return {
method: "pop"
};
}
toCloudJSON() {
return {
action: "delete",
nth: "last"
};
}
toString() {
return `删除云列表 ${this.data.name} 最后一项`;
}
}