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

remove more unused code, #38414

上级 f657b94f
......@@ -120,10 +120,6 @@ export function assign(destination: any, ...sources: any[]): any {
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 {
if (one === other) {
return true;
......
......@@ -4,51 +4,17 @@
*--------------------------------------------------------------------------------------------*/
'use strict';
import { illegalArgument } from 'vs/base/common/errors';
import * as instantiation from './instantiation';
export class AbstractDescriptor<T> {
constructor(private _staticArguments: any[]) {
// empty
}
public appendStaticArguments(more: any[]): void {
this._staticArguments.push.apply(this._staticArguments, more);
}
export class SyncDescriptor<T> {
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];
}
}
readonly ctor: any;
readonly staticArguments: any[];
_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[]) {
super(staticArguments);
}
public get ctor(): any {
return this._ctor;
}
protected bind(...moreStaticArguments: any[]): SyncDescriptor<T> {
let allArgs: any[] = [];
allArgs = allArgs.concat(this.staticArguments());
allArgs = allArgs.concat(moreStaticArguments);
return new SyncDescriptor<T>(this._ctor, ...allArgs);
constructor(ctor: new (...args: any[]) => T, ..._staticArguments: any[]) {
this.ctor = ctor;
this.staticArguments = _staticArguments;
}
}
......@@ -175,4 +141,4 @@ export interface SyncDescriptor8<A1, A2, A3, A4, A5, A6, A7, A8, T> {
bind(a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6): SyncDescriptor2<A7, A8, T>;
bind(a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6, a7: A7): SyncDescriptor1<A8, T>;
bind(a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6, a7: A7, a8: A8): SyncDescriptor0<T>;
}
\ No newline at end of file
}
......@@ -77,7 +77,7 @@ export class InstantiationService implements IInstantiationService {
private _createInstance<T>(desc: SyncDescriptor<T>, args: any[]): T {
// 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
let serviceDependencies = _util.getServiceDependencies(desc.ctor).sort((a, b) => a.index - b.index);
......@@ -117,9 +117,7 @@ export class InstantiationService implements IInstantiationService {
argArray.push(...staticArgs);
argArray.push(...serviceArgs);
const instance = create.apply(null, argArray);
desc._validate(instance);
return <T>instance;
return <T>create.apply(null, argArray);
}
private _getOrCreateServiceInstance<T>(id: ServiceIdentifier<T>): T {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册