version-bridge: remove getGlobalSingleton

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2021-09-11 13:03:05 +02:00
parent 921569b500
commit 00fee0b11d
7 changed files with 16 additions and 71 deletions
@@ -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.
*
+1 -1
View File
@@ -14,7 +14,7 @@
* limitations under the License.
*/
export { getGlobalSingleton, getOrCreateGlobalSingleton } from './globalObject';
export { getOrCreateGlobalSingleton } from './globalObject';
export {
createVersionedContextForTesting,
useVersionedContext,