mirror of
https://github.com/hanzoai/ui.git
synced 2026-11-20 22:36:27 +00:00
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]>
60 lines
1.4 KiB
TypeScript
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
|
|
}
|
|
|