X-Git-Url: https://git.josue.xyz/?p=VSoRC%2F.git;a=blobdiff_plain;f=node_modules%2Fxterm%2Fsrc%2Fcommon%2Fservices%2FInstantiationService.ts;fp=node_modules%2Fxterm%2Fsrc%2Fcommon%2Fservices%2FInstantiationService.ts;h=0000000000000000000000000000000000000000;hp=abce8ac54ed267dc46c5ee7aa83c1d9164ed7b4f;hb=5e96dd57ddd883604e87f62bdddcb111c63a6e1a;hpb=acb5f682a2b75b972710cabd81658f63071324b0 diff --git a/node_modules/xterm/src/common/services/InstantiationService.ts b/node_modules/xterm/src/common/services/InstantiationService.ts deleted file mode 100644 index abce8ac..0000000 --- a/node_modules/xterm/src/common/services/InstantiationService.ts +++ /dev/null @@ -1,77 +0,0 @@ -/** - * Copyright (c) 2019 The xterm.js authors. All rights reserved. - * @license MIT - * - * This was heavily inspired from microsoft/vscode's dependency injection system (MIT). - */ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - -import { IInstantiationService, IServiceIdentifier } from 'common/services/Services'; -import { getServiceDependencies } from 'common/services/ServiceRegistry'; - -export class ServiceCollection { - - private _entries = new Map, any>(); - - constructor(...entries: [IServiceIdentifier, any][]) { - for (const [id, service] of entries) { - this.set(id, service); - } - } - - set(id: IServiceIdentifier, instance: T): T { - const result = this._entries.get(id); - this._entries.set(id, instance); - return result; - } - - forEach(callback: (id: IServiceIdentifier, instance: any) => any): void { - this._entries.forEach((value, key) => callback(key, value)); - } - - has(id: IServiceIdentifier): boolean { - return this._entries.has(id); - } - - get(id: IServiceIdentifier): T { - return this._entries.get(id); - } -} - -export class InstantiationService implements IInstantiationService { - private readonly _services: ServiceCollection = new ServiceCollection(); - - constructor() { - this._services.set(IInstantiationService, this); - } - - public setService(id: IServiceIdentifier, instance: T): void { - this._services.set(id, instance); - } - - public createInstance(ctor: any, ...args: any[]): any { - const serviceDependencies = getServiceDependencies(ctor).sort((a, b) => a.index - b.index); - - const serviceArgs: any[] = []; - for (const dependency of serviceDependencies) { - const service = this._services.get(dependency.id); - if (!service) { - throw new Error(`[createInstance] ${ctor.name} depends on UNKNOWN service ${dependency.id}.`); - } - serviceArgs.push(service); - } - - const firstServiceArgPos = serviceDependencies.length > 0 ? serviceDependencies[0].index : args.length; - - // check for argument mismatches, adjust static args if needed - if (args.length !== firstServiceArgPos) { - throw new Error(`[createInstance] First service dependency of ${ctor.name} at position ${firstServiceArgPos + 1} conflicts with ${args.length} static arguments`); - } - - // now create the instance - return new ctor(...[...args, ...serviceArgs]); - } -}