kitten-cloud-function
Version:
用于编程猫源码云功能(云变量、云列表等)的客户端工具
58 lines (57 loc) • 1.44 kB
JavaScript
import { None } from "../other";
export 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 != 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]();
}
}