Files
zeekayandHanzo Dev 57f9435929 Keep every package in one directory
The workspace declared pkg/* and pkgs/* both, so one repo had two names
for one concept and a package's home was a coin toss. The shared build
tooling already lived in pkg/ui/scripts and pkgs reached back into it
two levels up; now it is a sibling. hanzo.yml gates on pkg/ui, so the
published library stays where CI already looks and the rest joins it.

The publish glob follows: one root, one pattern, nothing invisible to it.

Co-authored-by: Hanzo Dev <[email protected]>
2026-09-08 23:50:28 -07:00

60 lines
1.4 KiB
TypeScript

import type { CommerceService, CommerceConfig } from '../../../types'
import { StandaloneService } from './index'
import { initSelectionUI } from '../../../util'
import { readSnapshot, writeSnapshotsOnChange } from './persistence'
const _LOG = false
const _log = (s: string) => {
if (!_LOG) return;
const d = new Date()
console.log(`TIMESTAMPED: ${d.getUTCMinutes()}:${d.getUTCSeconds()}:${d.getUTCMilliseconds()}`)
console.log(s)
}
let instance: StandaloneService | undefined = undefined
export const getInstance = ({
families,
rootNode,
options,
uiSpecifiers
}: CommerceConfig) : CommerceService => {
if (!options) {
throw new Error('cmmc getInstance(): Standalone Commerce Service requires config options!')
}
if (typeof window === "undefined") {
if (uiSpecifiers) {
initSelectionUI(uiSpecifiers)
}
_log("NEW INSTANCE: SERVER") //////////
return new StandaloneService(
families,
rootNode,
options
)
}
// Client side, create the store only once in the client
if (!instance) {
if (uiSpecifiers) {
initSelectionUI(uiSpecifiers)
}
_log("NEW INSTANCE: CLIENT") ///////////
const snapShot = readSnapshot(options.localStorageKey)
instance = new StandaloneService(
families,
rootNode,
options,
snapShot
)
writeSnapshotsOnChange(instance, options.localStorageKey)
}
return instance
}