UNPKG

typir

Version:

General purpose type checking library

36 lines 1.17 kB
/****************************************************************************** * Copyright 2024 TypeFox GmbH * This program and the accompanying materials are made available under the * terms of the MIT License, which is available in the project root. ******************************************************************************/ export class DefaultKindRegistry { constructor(services) { this.kinds = new Map(); // name of kind => kind (for an easier look-up) this.services = services; } register(kind) { const key = kind.$name; if (this.kinds.has(key)) { if (this.kinds.get(key) === kind) { // that is OK } else { throw new Error(`duplicate kind named '${key}'`); } } else { this.kinds.set(key, kind); } } get($name) { return this.kinds.get($name); } getOrCreateKind($name, factory) { const existing = this.get($name); if (existing) { return existing; } return factory(this.services); } } //# sourceMappingURL=kind-registry.js.map