Skip to content

Commit 3ca1f6d

Browse files
committed
chore: fix tests
1 parent a730379 commit 3ca1f6d

12 files changed

Lines changed: 310 additions & 347 deletions

File tree

packages/svelte-db/package.json

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
"description": "Svelte integration for @tanstack/db",
44
"version": "0.0.0",
55
"scripts": {
6-
"dev": "vite dev",
7-
"build": "vite build && npm run prepack",
8-
"preview": "vite preview",
9-
"prepare": "svelte-kit sync || echo ''",
10-
"prepack": "svelte-kit sync && svelte-package && publint",
11-
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
12-
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
13-
"test": "npx vitest --run"
6+
"test:types": "svelte-check --tsconfig ./tsconfig.json",
7+
"test:eslint": "eslint ./src ./tests",
8+
"test:lib": "vitest",
9+
"test:lib:dev": "pnpm run test:lib --watch",
10+
"test:build": "publint --strict",
11+
"test": "npx vitest --run",
12+
"build": "svelte-package --input ./src --output ./dist"
1413
},
1514
"files": [
1615
"dist",

packages/svelte-db/src/app.d.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

packages/svelte-db/src/app.html

Lines changed: 0 additions & 12 deletions
This file was deleted.

packages/svelte-db/src/routes/+page.svelte

Lines changed: 0 additions & 3 deletions
This file was deleted.

packages/svelte-db/src/lib/useLiveQuery.svelte.ts renamed to packages/svelte-db/src/useLiveQuery.svelte.ts

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,6 @@ import type {
99
Schema,
1010
} from "@tanstack/db"
1111

12-
type ComputedRef<T> = {
13-
get current(): T
14-
}
15-
16-
type Getter<T> = () => T
17-
18-
function toValue<T>() {}
19-
2012
export interface UseLiveQueryReturn<T extends object> {
2113
state: Map<string, T>
2214
data: Array<T>
@@ -29,41 +21,38 @@ export function useLiveQuery<
2921
queryFn: (
3022
q: InitialQueryBuilder<Context<Schema>>
3123
) => QueryBuilder<TResultContext>,
32-
deps: Array<Getter<unknown>> = []
24+
deps: Array<() => unknown> = []
3325
): UseLiveQueryReturn<ResultsFromContext<TResultContext>> {
3426
const compiledQuery = $derived.by(() => {
3527
// Just reference deps to make derived reactive to them
36-
// deps.forEach((dep) => toValue(dep))
28+
deps.forEach((dep) => dep())
3729

3830
const query = queryFn(queryBuilder())
3931
const compiled = compileQuery(query)
4032
compiled.start()
4133
return compiled
4234
})
4335

44-
const state = $derived(useStore(compiledQuery.results.derivedState).current)
45-
const data = $derived(useStore(compiledQuery.results.derivedArray).current)
46-
const collection = $derived(compiledQuery.results)
36+
const state = () => useStore(compiledQuery.results.derivedState).current
37+
const data = () => useStore(compiledQuery.results.derivedArray).current
4738

4839
$effect(() => {
49-
if (compiledQuery.state === `stopped`) {
50-
compiledQuery.start()
51-
}
52-
5340
return () => {
5441
compiledQuery.stop()
5542
}
5643
})
5744

5845
return {
5946
get state() {
60-
return state
47+
return state()
6148
},
6249
get data() {
63-
return data
50+
return data()
6451
},
6552
get collection() {
66-
return collection as any
53+
return compiledQuery.results as unknown as Collection<
54+
ResultsFromContext<TResultContext>
55+
>
6756
},
6857
}
6958
}
File renamed without changes.
-1.53 KB
Binary file not shown.
Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,7 @@
1-
import adapter from '@sveltejs/adapter-auto';
2-
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
1+
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'
32

4-
/** @type {import('@sveltejs/kit').Config} */
53
const config = {
6-
// Consult https://svelte.dev/docs/kit/integrations
7-
// for more information about preprocessors
8-
preprocess: vitePreprocess(),
4+
preprocess: vitePreprocess(),
5+
}
96

10-
kit: {
11-
// adapter-auto only supports some environments, see https://svelte.dev/docs/kit/adapter-auto for a list.
12-
// If your environment is not supported, or you settled on a specific environment, switch out the adapter.
13-
// See https://svelte.dev/docs/kit/adapters for more information about adapters.
14-
adapter: adapter()
15-
}
16-
};
17-
18-
export default config;
7+
export default config

0 commit comments

Comments
 (0)