提交 f29abe48 编写于 作者: J Johannes Rieken

remove more unused code, #38414

上级 f657b94f
...@@ -120,10 +120,6 @@ export function assign(destination: any, ...sources: any[]): any { ...@@ -120,10 +120,6 @@ export function assign(destination: any, ...sources: any[]): any {
return destination; return destination;
} }
export function toObject<T>(arr: T[], keyMap: (t: T) => string): { [key: string]: T } {
return arr.reduce((o, d) => assign(o, { [keyMap(d)]: d }), Object.create(null));
}
export function equals(one: any, other: any): boolean { export function equals(one: any, other: any): boolean {
if (one === other) { if (one === other) {
return true; return true;
......
...@@ -4,51 +4,17 @@ ...@@ -4,51 +4,17 @@
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
'use strict'; 'use strict';
import { illegalArgument } from 'vs/base/common/errors';
import * as instantiation from './instantiation'; import * as instantiation from './instantiation';
export class AbstractDescriptor<T> {
constructor(private _staticArguments: any[]) { export class SyncDescriptor<T> {
// empty
}
public appendStaticArguments(more: any[]): void {
this._staticArguments.push.apply(this._staticArguments, more);
}
public staticArguments(): any[];
public staticArguments(nth: number): any;
public staticArguments(nth?: number): any[] {
if (isNaN(nth)) {
return this._staticArguments.slice(0);
} else {
return this._staticArguments[nth];
}
}
_validate(type: T): void {
if (!type) {
throw illegalArgument('can not be falsy');
}
}
}
export class SyncDescriptor<T> extends AbstractDescriptor<T> {
constructor(private _ctor: any, ...staticArguments: any[]) { readonly ctor: any;
super(staticArguments); readonly staticArguments: any[];
}
public get ctor(): any {
return this._ctor;
}
protected bind(...moreStaticArguments: any[]): SyncDescriptor<T> { constructor(ctor: new (...args: any[]) => T, ..._staticArguments: any[]) {
let allArgs: any[] = []; this.ctor = ctor;
allArgs = allArgs.concat(this.staticArguments()); this.staticArguments = _staticArguments;
allArgs = allArgs.concat(moreStaticArguments);
return new SyncDescriptor<T>(this._ctor, ...allArgs);
} }
} }
......
...@@ -77,7 +77,7 @@ export class InstantiationService implements IInstantiationService { ...@@ -77,7 +77,7 @@ export class InstantiationService implements IInstantiationService {
private _createInstance<T>(desc: SyncDescriptor<T>, args: any[]): T { private _createInstance<T>(desc: SyncDescriptor<T>, args: any[]): T {
// arguments given by createInstance-call and/or the descriptor // arguments given by createInstance-call and/or the descriptor
let staticArgs = desc.staticArguments().concat(args); let staticArgs = desc.staticArguments.concat(args);
// arguments defined by service decorators // arguments defined by service decorators
let serviceDependencies = _util.getServiceDependencies(desc.ctor).sort((a, b) => a.index - b.index); let serviceDependencies = _util.getServiceDependencies(desc.ctor).sort((a, b) => a.index - b.index);
...@@ -117,9 +117,7 @@ export class InstantiationService implements IInstantiationService { ...@@ -117,9 +117,7 @@ export class InstantiationService implements IInstantiationService {
argArray.push(...staticArgs); argArray.push(...staticArgs);
argArray.push(...serviceArgs); argArray.push(...serviceArgs);
const instance = create.apply(null, argArray); return <T>create.apply(null, argArray);
desc._validate(instance);
return <T>instance;
} }
private _getOrCreateServiceInstance<T>(id: ServiceIdentifier<T>): T { private _getOrCreateServiceInstance<T>(id: ServiceIdentifier<T>): T {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册