UNPKG

kitten-cloud-function

Version:

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

62 lines (61 loc) 1.99 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.KittenCloudListPopCommand = 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 KittenCloudListPopCommand extends kitten_cloud_list_update_command_1.KittenCloudListUpdateCommand { constructor(source, list) { super(source, list); this.list = list; this.effective = other_1.None; this.backup = 0; } execute() { if (this.effective != other_1.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 == other_1.None) { throw new Error("无法撤销命令:命令尚未执行"); } if (this.effective) { this.list.value.push(this.backup); this.list.pushed.emit({ source: kitten_cloud_data_update_source_1.KittenCloudDataUpdateSource.REVOKE, item: this.backup }); } this.effective = other_1.None; } isEffective() { return this.effective == other_1.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} 最后一项`; } } exports.KittenCloudListPopCommand = KittenCloudListPopCommand;