UNPKG

kitten-cloud-function

Version:

用于编程猫源码云功能(云变量、云列表等)的客户端工具

55 lines (54 loc) 1.53 kB
import { None } from "../../../../utils/other"; import { KittenCloudDataUpdateSource } from "../kitten-cloud-data-update-source"; import { KittenCloudListUpdateCommand } from "./kitten-cloud-list-update-command"; export class KittenCloudListEmptyCommand extends KittenCloudListUpdateCommand { constructor(source, list) { super(source, list); this.list = list; this.backup = None; } execute() { if (this.backup != None) { throw new Error("无法执行命令:命令已被执行,不能重复执行"); } this.backup = this.list.value; this.list.value = []; this.list.emptied.emit({ source: this.source, list: this.backup.slice() }); } revoke() { if (this.backup == None) { throw new Error("无法撤销命令:命令尚未执行"); } this.list.value = this.backup; this.list.replacedAll.emit({ source: KittenCloudDataUpdateSource.REVOKE, originalList: [], newList: this.backup.slice() }); this.backup = None; } isEffective() { return true; } isLegal() { return true; } toJSON() { return { method: "empty" }; } toCloudJSON() { return { action: "delete", cvid: this.list.cvid, nth: "all" }; } toString() { return `清空云列表 ${this.data.name} `; } }