mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-03-21 20:30:29 -04:00
* Merge from vscode 81d7885dc2e9dc617e1522697a2966bc4025a45d * Fix vs unit tests and hygiene issue * Fix strict null check issue
54 lines
1.5 KiB
TypeScript
54 lines
1.5 KiB
TypeScript
/*---------------------------------------------------------------------------------------------
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
|
*--------------------------------------------------------------------------------------------*/
|
|
|
|
import * as Types from 'vs/base/common/types';
|
|
import * as Assert from 'vs/base/common/assert';
|
|
|
|
export interface IRegistry {
|
|
|
|
/**
|
|
* Adds the extension functions and properties defined by data to the
|
|
* platform. The provided id must be unique.
|
|
* @param id a unique identifier
|
|
* @param data a contribution
|
|
*/
|
|
add(id: string, data: any): void;
|
|
|
|
/**
|
|
* Returns true iff there is an extension with the provided id.
|
|
* @param id an extension identifier
|
|
*/
|
|
knows(id: string): boolean;
|
|
|
|
/**
|
|
* Returns the extension functions and properties defined by the specified key or null.
|
|
* @param id an extension identifier
|
|
*/
|
|
as<T>(id: string): T;
|
|
}
|
|
|
|
class RegistryImpl implements IRegistry {
|
|
|
|
private readonly data = new Map<string, any>();
|
|
|
|
public add(id: string, data: any): void {
|
|
Assert.ok(Types.isString(id));
|
|
Assert.ok(Types.isObject(data));
|
|
Assert.ok(!this.data.has(id), 'There is already an extension with this id');
|
|
|
|
this.data.set(id, data);
|
|
}
|
|
|
|
public knows(id: string): boolean {
|
|
return this.data.has(id);
|
|
}
|
|
|
|
public as(id: string): any {
|
|
return this.data.get(id) || null;
|
|
}
|
|
}
|
|
|
|
export const Registry: IRegistry = new RegistryImpl();
|