思维导图
程序员文章站
2022-04-06 12:27:55
...
var commands = {
up: 1,
down: 2,
father: 3,
child: 4,
};
var commandHandlerFactory = new CommandHandlerFactory();
function Task(content, parent) {
this.content = content;
this.childTask = [];
this.parent = parent;
this.addChildTask = function (childContent) {
this.childTask.push(new Task(childContent));
};
this.remove = function () {
this.parent.childTask.remove(this);
};
this.edit = function (newContent) {
this.content = newContent;
};
}
function Mind(name) {
this.task = new Task(name, null);
this.selectTask = this.task;
this.keyDown = function (e) {
executeCommand(this.selectTask, e);
};
}
function executeCommand(selectedTask, e) {
var command = getCommand(e);
var handler = commandHandlerFactory.getCommandHandler(command);
handler.execute(selectedTask);
}
function CommandHandlerFactory() {
this.commandHandlers = [];
this.addCommandHandler = function (command, commandHandler) {
this.commandHandlers.push({ conmmand: command, commandHandler: commandHandler });
};
this.getCommandHandler = function (command) {
for (var i = 0; i < this.commandHandlers.length; i++) {
if (this.commandHandlers.command == command) {
return this.commandHandlers.commandHandler;
}
}
};
}
function getCommand(e) {
//TODO:need to check return which command
return commands.up;
}
转载于:https://my.oschina.net/u/254394/blog/373774