UNPKG

kitten-cloud-function

Version:

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

69 lines (68 loc) 2.43 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.KittenCloudListAddCommand = 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 KittenCloudListAddCommand extends kitten_cloud_list_update_command_1.KittenCloudListUpdateCommand { constructor(source, list, index, value) { super(source, list); this.list = list; this.index = index; this.value = value; this.effective = other_1.None; } execute() { if (this.effective != other_1.None) { throw new Error("无法执行命令:命令已被执行,不能重复执行"); } this.effective = 0 <= this.index && this.index <= this.list.length; if (this.effective) { this.list.value.splice(this.index, 0, this.value); this.effective = true; this.list.added.emit({ source: this.source, index: this.index, item: this.value }); } } revoke() { if (this.effective == other_1.None) { throw new Error("无法撤销命令:命令尚未执行"); } if (this.effective) { this.list.value.splice(this.index, 1); this.list.removed.emit({ source: kitten_cloud_data_update_source_1.KittenCloudDataUpdateSource.REVOKE, index: this.index, item: this.value }); } this.effective = other_1.None; } isEffective() { return this.effective == other_1.None ? 0 <= this.index && this.index <= this.list.length : this.effective; } isLegal() { return 0 <= this.index && this.index < this.data.listLengthLimit.value; } toJSON() { return { method: "add", index: this.index }; } toCloudJSON() { return { action: "insert", cvid: this.list.cvid, nth: this.index + 1, value: this.value }; } toString() { return `添加 ${JSON.stringify(this.value)} 到云列表 ${this.data.name} 第 ${this.index + 1} 项`; } } exports.KittenCloudListAddCommand = KittenCloudListAddCommand;