debt - use Map instead of object

This commit is contained in:
Johannes Rieken
2016-12-30 15:37:12 +01:00
parent 8385b8c8bc
commit 118b3e0d5a
9 changed files with 110 additions and 117 deletions

View File

@@ -26,7 +26,7 @@ interface CommandHandler {
export class ExtHostCommands extends ExtHostCommandsShape {
private _commands: { [n: string]: CommandHandler } = Object.create(null);
private _commands = new Map<string, CommandHandler>();
private _proxy: MainThreadCommandsShape;
private _extHostEditors: ExtHostEditors;
private _converter: CommandsConverter;
@@ -52,15 +52,15 @@ export class ExtHostCommands extends ExtHostCommandsShape {
throw new Error('invalid id');
}
if (this._commands[id]) {
if (this._commands.has(id)) {
throw new Error('command with id already exists');
}
this._commands[id] = { callback, thisArg, description };
this._commands.set(id, { callback, thisArg, description });
this._proxy.$registerCommand(id);
return new extHostTypes.Disposable(() => {
if (delete this._commands[id]) {
if (this._commands.delete(id)) {
this._proxy.$unregisterCommand(id);
}
});
@@ -68,7 +68,7 @@ export class ExtHostCommands extends ExtHostCommandsShape {
executeCommand<T>(id: string, ...args: any[]): Thenable<T> {
if (this._commands[id]) {
if (this._commands.has(id)) {
// we stay inside the extension host and support
// to pass any kind of parameters around
return this.$executeContributedCommand(id, ...args);
@@ -97,7 +97,7 @@ export class ExtHostCommands extends ExtHostCommandsShape {
}
$executeContributedCommand<T>(id: string, ...args: any[]): Thenable<T> {
let command = this._commands[id];
let command = this._commands.get(id);
if (!command) {
return TPromise.wrapError<T>(`Contributed command '${id}' does not exist.`);
}
@@ -139,12 +139,12 @@ export class ExtHostCommands extends ExtHostCommandsShape {
$getContributedCommandHandlerDescriptions(): TPromise<{ [id: string]: string | ICommandHandlerDescription }> {
const result: { [id: string]: string | ICommandHandlerDescription } = Object.create(null);
for (let id in this._commands) {
let {description} = this._commands[id];
this._commands.forEach((command, id) => {
let {description} = command;
if (description) {
result[id] = description;
}
}
});
return TPromise.as(result);
}
}
@@ -212,4 +212,4 @@ export class CommandsConverter {
return this._commands.executeCommand(actualCmd.command, ...actualCmd.arguments);
}
}
}