UNPKG

kitten-cloud-function

Version:

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

60 lines (59 loc) 1.84 kB
import { None } from "../../../../utils/other"; import { KittenCloudDataUpdateSource } from "../kitten-cloud-data-update-source"; import { KittenCloudListUpdateCommand } from "./kitten-cloud-list-update-command"; export class KittenCloudListPushCommand extends KittenCloudListUpdateCommand { constructor(source, list, value) { super(source, list); this.list = list; this.value = value; this.effective = None; } execute() { if (this.effective != 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 == None) { throw new Error("无法撤销命令:命令尚未执行"); } if (this.effective) { this.list.value.pop(); this.list.popped.emit({ source: KittenCloudDataUpdateSource.REVOKE, item: this.value }); } this.effective = None; } isEffective() { return this.effective == 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} 末项`; } }