Skip to content

Commit

Permalink
persist data source branch in localStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesdabbs committed Dec 9, 2023
1 parent ab6e45f commit 4bd4a10
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 31 deletions.
40 changes: 25 additions & 15 deletions packages/viewer/src/context.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
export type { Context } from './context/types'

import { getContext, setContext } from 'svelte'
import { type Readable, derived } from 'svelte/store'
import { formula as F } from '@pi-base/core'

import type { Context } from './context/types'
import { trace } from './debug'
import * as Errors from './errors'
import type * as Gateway from './gateway'
import { Id } from './models'
import { renderer } from './parser'
import { type Local, local } from './repositories'
import { type Prestore, type Store, create } from './stores'
import { subscribeUntil } from './util'
import { getContext, setContext } from 'svelte'
import { derived, get, type Readable } from 'svelte/store'

import type { Context } from '@/context/types'
import { trace } from '@/debug'
import * as Errors from '@/errors'
import type * as Gateway from '@/gateway'
import { Id } from '@/models'
import { renderer } from '@/parser'
import { local, type Local } from '@/repositories'
import { create, type Prestore, type Store } from '@/stores'
import { type Source } from '@/types'
import { subscribeUntil } from '@/util'

export type Config = {
showDevLink: boolean
Expand All @@ -39,20 +40,29 @@ function project(store: Store) {
export function initialize({
db = local(),
errorHandler = Errors.log(),
host,
source = {},
gateway,
showDev = false,
typesetter = renderer,
}: {
db?: Local<Prestore>
errorHandler?: Errors.Handler
host?: string
source?: Partial<Source>
gateway: Gateway.Sync
showDev?: boolean
typesetter?: typeof renderer
}): Context {
const pre = db.load()
const store = create(pre, gateway, { host })
const store = create(
{
...pre,
source: {
host: source.host || pre.source.host,
branch: source.branch || pre.source.branch,
},
},
gateway,
)

db.subscribe(project(store))

Expand Down
4 changes: 3 additions & 1 deletion packages/viewer/src/routes/+layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ export const load: LayoutLoad = async ({ fetch, url: { host } }) => {
showDev: dev,
errorHandler,
gateway: sync(fetch),
host: bundleHost,
source: {
host: bundleHost,
},
})

await context.loaded()
Expand Down
17 changes: 2 additions & 15 deletions packages/viewer/src/stores/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,12 @@ export type Store = {
deduction: Deduction.Store
}

export function create(
pre: Prestore,
gateway: Gateway.Sync,
{
host = defaultHost,
branch = mainBranch,
}: {
host?: string
branch?: string
} = {},
): Store {
export function create(pre: Prestore, gateway: Gateway.Sync): Store {
const spaces = writable(Collection.empty<Space>())
const properties = writable(Collection.empty<Property>())
const theorems = writable(new Theorems())
const traits = writable(new Traits())
const source = Source.create({
host,
branch,
})
const source = Source.create(pre.source)
const sync = Sync.create(refresh, pre.sync)

const deduction = Deduction.create(
Expand Down

0 comments on commit 4bd4a10

Please sign in to comment.