version-bridge: remove getGlobalSingleton
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -25,9 +25,6 @@ export function createVersionedValueMap<
|
||||
},
|
||||
>(versions: Versions): VersionedValue<Versions>;
|
||||
|
||||
// @public
|
||||
export function getGlobalSingleton<T>(id: string): T;
|
||||
|
||||
// @public
|
||||
export function getOrCreateGlobalSingleton<T>(id: string, supplier: () => T): T;
|
||||
|
||||
|
||||
@@ -14,33 +14,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { getGlobalSingleton, getOrCreateGlobalSingleton } from './globalObject';
|
||||
import { getOrCreateGlobalSingleton } from './globalObject';
|
||||
|
||||
const anyGlobal = global as any;
|
||||
|
||||
describe('getGlobalSingleton', () => {
|
||||
beforeEach(() => {
|
||||
delete anyGlobal['__@backstage/my-thing__'];
|
||||
});
|
||||
|
||||
it('should return an existing value', () => {
|
||||
const myThing = {};
|
||||
const myOtherThing = {};
|
||||
|
||||
anyGlobal['__@backstage/my-thing__'] = myThing;
|
||||
expect(getGlobalSingleton('my-thing')).toBe(myThing);
|
||||
expect(getGlobalSingleton('my-thing')).toBe(myThing);
|
||||
anyGlobal['__@backstage/my-thing__'] = myOtherThing;
|
||||
expect(getGlobalSingleton('my-thing')).toBe(myOtherThing);
|
||||
});
|
||||
|
||||
it('should throw if the value is not set', () => {
|
||||
expect(() => getGlobalSingleton('my-thing')).toThrow(
|
||||
'Global my-thing is not set',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getOrCreateGlobalSingleton', () => {
|
||||
beforeEach(() => {
|
||||
delete anyGlobal['__@backstage/my-thing__'];
|
||||
|
||||
@@ -30,20 +30,6 @@ const globalObject = getGlobalObject();
|
||||
|
||||
const makeKey = (id: string) => `__@backstage/${id}__`;
|
||||
|
||||
/**
|
||||
* Used to access a global singleton value, failing if it is not already set.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export function getGlobalSingleton<T>(id: string): T {
|
||||
const key = makeKey(id);
|
||||
if (!(key in globalObject)) {
|
||||
throw new Error(`Global ${id} is not set`);
|
||||
}
|
||||
|
||||
return globalObject[key];
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes access to a global singleton value, with the first caller creating the value.
|
||||
*
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export { getGlobalSingleton, getOrCreateGlobalSingleton } from './globalObject';
|
||||
export { getOrCreateGlobalSingleton } from './globalObject';
|
||||
export {
|
||||
createVersionedContextForTesting,
|
||||
useVersionedContext,
|
||||
|
||||
Reference in New Issue
Block a user