Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default [
{
ignores: [
'dist/**',
'lib/**',
'node_modules/**',
'coverage/**'
],
Expand Down
49 changes: 32 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 10 additions & 3 deletions src/logic/solidLogicSingleton.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as debug from '../util/debug'
import { authSession } from '../authSession/authSession'
import { createSolidLogic } from './solidLogic'
import { SolidLogic } from '../types'

const _fetch = async (url, requestInit) => {
const omitCreds = requestInit && requestInit.credentials && requestInit.credentials == 'omit'
Expand All @@ -14,17 +15,23 @@ const _fetch = async (url, requestInit) => {

// Global singleton pattern to ensure unique store across library versions
const SINGLETON_SYMBOL = Symbol.for('solid-logic-singleton')
const globalThis = (typeof window !== 'undefined' ? window : global) as any

function getOrCreateSingleton() {
// Type the global object properly with the singleton
interface GlobalWithSingleton {
[SINGLETON_SYMBOL]?: SolidLogic
}

const globalThis = (typeof window !== 'undefined' ? window : global) as GlobalWithSingleton

function getOrCreateSingleton(): SolidLogic {
if (!globalThis[SINGLETON_SYMBOL]) {
debug.log('SolidLogic: Creating new global singleton instance.')
globalThis[SINGLETON_SYMBOL] = createSolidLogic({ fetch: _fetch }, authSession)
debug.log('Unique quadstore initialized.')
} else {
debug.log('SolidLogic: Using existing global singleton instance.')
}
return globalThis[SINGLETON_SYMBOL]
return globalThis[SINGLETON_SYMBOL]!
}
//this const makes solidLogicSingleton global accessible in mashlib
const solidLogicSingleton = getOrCreateSingleton()
Expand Down
Loading