Skip to content

Commit 393962b

Browse files
committed
address PR review
1 parent bdae9bb commit 393962b

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

packages/hub/src/hub.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ export function getHubFromCarrier(carrier: Carrier): Hub {
636636
*/
637637
export function setHubOnCarrier(carrier: Carrier, hub: Hub): boolean {
638638
if (!carrier) return false;
639-
const sentry = (carrier.__SENTRY__ = carrier.__SENTRY__ || {});
640-
sentry.hub = hub;
639+
const __SENTRY__ = (carrier.__SENTRY__ = carrier.__SENTRY__ || {});
640+
__SENTRY__.hub = hub;
641641
return true;
642642
}

packages/utils/src/global.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,19 @@ export function getGlobalObject<T>(): T & SentryGlobal {
4646
}
4747

4848
/**
49-
* Returns a global singleton contained on the global `__SENTRY__` object.
49+
* Returns a global singleton contained in the global `__SENTRY__` object.
50+
*
51+
* If the singleton doesn't already exist in `__SENTRY__`, it will be created using the given factory
52+
* function and added to the `__SENTRY__` object.
5053
*
5154
* @param name name of the global singleton on __SENTRY__
52-
* @param creator creation function
55+
* @param creator creator Factory function to create the singleton if it doesn't already exist on `__SENTRY__`
56+
* @param obj (Optional) The global object on which to look for `__SENTRY__`, if not `getGlobalObject`'s return value
5357
* @returns the singleton
5458
*/
5559
export function getGlobalSingleton<T>(name: keyof SentryGlobal['__SENTRY__'], creator: () => T, obj?: unknown): T {
5660
const global = (obj || getGlobalObject()) as SentryGlobal;
57-
const sentry = (global.__SENTRY__ = global.__SENTRY__ || {});
58-
return sentry[name] || (sentry[name] = creator());
61+
const __SENTRY__ = (global.__SENTRY__ = global.__SENTRY__ || {});
62+
const singleton = __SENTRY__[name] || (__SENTRY__[name] = creator());
63+
return singleton;
5964
}

0 commit comments

Comments
 (0)