kitten-cloud-function
Version:
用于编程猫源码云功能(云变量、云列表等)的客户端工具
62 lines (61 loc) • 1.59 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.CommandGroup = void 0;
const other_1 = require("../other");
class CommandGroup {
constructor(commandArray = []) {
this.commandArray = commandArray;
}
execute() {
for (const command of this.commandArray) {
command.execute();
}
}
get(index) {
return this.commandArray[index];
}
get length() {
return this.commandArray.length;
}
add(command) {
const lastCommand = this.commandArray.slice(-1)[0];
if (lastCommand != other_1.None && "merge" in lastCommand && typeof lastCommand.merge == "function") {
try {
lastCommand.merge(command);
}
catch (error) {
this.commandArray.push(command);
}
}
else {
this.commandArray.push(command);
}
}
addAll(commands) {
if (commands instanceof CommandGroup) {
commands = commands.commandArray;
}
for (const command of commands) {
this.add(command);
}
}
isEmpty() {
return this.commandArray.length == 0;
}
first() {
return this.commandArray[0];
}
last() {
return this.commandArray.slice(-1)[0];
}
shift() {
return this.commandArray.shift();
}
pop() {
return this.commandArray.pop();
}
[Symbol.iterator]() {
return this.commandArray[Symbol.iterator]();
}
}
exports.CommandGroup = CommandGroup;
;