11import * as debug from '../util/debug'
22import { authSession } from '../authSession/authSession'
33import { createSolidLogic } from './solidLogic'
4+ import { SolidLogic } from '../types'
45
56const _fetch = async ( url , requestInit ) => {
67 const omitCreds = requestInit && requestInit . credentials && requestInit . credentials == 'omit'
@@ -14,17 +15,23 @@ const _fetch = async (url, requestInit) => {
1415
1516// Global singleton pattern to ensure unique store across library versions
1617const SINGLETON_SYMBOL = Symbol . for ( 'solid-logic-singleton' )
17- const globalThis = ( typeof window !== 'undefined' ? window : global ) as any
1818
19- function getOrCreateSingleton ( ) {
19+ // Type the global object properly with the singleton
20+ interface GlobalWithSingleton {
21+ [ SINGLETON_SYMBOL ] ?: SolidLogic
22+ }
23+
24+ const globalThis = ( typeof window !== 'undefined' ? window : global ) as GlobalWithSingleton
25+
26+ function getOrCreateSingleton ( ) : SolidLogic {
2027 if ( ! globalThis [ SINGLETON_SYMBOL ] ) {
2128 debug . log ( 'SolidLogic: Creating new global singleton instance.' )
2229 globalThis [ SINGLETON_SYMBOL ] = createSolidLogic ( { fetch : _fetch } , authSession )
2330 debug . log ( 'Unique quadstore initialized.' )
2431 } else {
2532 debug . log ( 'SolidLogic: Using existing global singleton instance.' )
2633 }
27- return globalThis [ SINGLETON_SYMBOL ]
34+ return globalThis [ SINGLETON_SYMBOL ] !
2835}
2936//this const makes solidLogicSingleton global accessible in mashlib
3037const solidLogicSingleton = getOrCreateSingleton ( )
0 commit comments