@tanstack/svelte-db 0.1.91 → 0.1.94
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/useLiveQuery.svelte.js +11 -12
- package/package.json +2 -2
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { untrack } from 'svelte';
|
|
3
3
|
// eslint-disable-next-line import/no-duplicates -- See https://github.com/un-ts/eslint-plugin-import-x/issues/308
|
|
4
4
|
import { SvelteMap } from 'svelte/reactivity';
|
|
5
|
-
import { BaseQueryBuilder, createLiveQueryCollection } from '@tanstack/db';
|
|
5
|
+
import { BaseQueryBuilder, createLiveQueryCollection, isCollection, isSingleResultCollection, } from '@tanstack/db';
|
|
6
6
|
function toValue(value) {
|
|
7
7
|
if (typeof value === `function`) {
|
|
8
8
|
return value();
|
|
@@ -26,12 +26,8 @@ export function useLiveQuery(configOrQueryOrCollection, deps = []) {
|
|
|
26
26
|
unwrappedParam = configOrQueryOrCollection;
|
|
27
27
|
}
|
|
28
28
|
// Check if it's already a collection by checking for specific collection methods
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
typeof unwrappedParam.subscribeChanges === `function` &&
|
|
32
|
-
typeof unwrappedParam.startSyncImmediate === `function` &&
|
|
33
|
-
typeof unwrappedParam.id === `string`;
|
|
34
|
-
if (isCollection) {
|
|
29
|
+
const inputIsCollection = isCollection(unwrappedParam);
|
|
30
|
+
if (inputIsCollection) {
|
|
35
31
|
// Warn when passing a collection directly with on-demand sync mode
|
|
36
32
|
// In on-demand mode, data is only loaded when queries with predicates request it
|
|
37
33
|
// Passing the collection directly doesn't provide any predicates, so no data loads
|
|
@@ -68,6 +64,12 @@ export function useLiveQuery(configOrQueryOrCollection, deps = []) {
|
|
|
68
64
|
});
|
|
69
65
|
}
|
|
70
66
|
else {
|
|
67
|
+
// A reactive getter (or param-driven query fn) can resolve to null/undefined
|
|
68
|
+
// to mean "disabled". `toValue` above already called it, so guard here —
|
|
69
|
+
// otherwise `{ ...null }` reaches createLiveQueryCollection and throws.
|
|
70
|
+
if (unwrappedParam === undefined || unwrappedParam === null) {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
71
73
|
return createLiveQueryCollection({
|
|
72
74
|
...unwrappedParam,
|
|
73
75
|
startSync: true,
|
|
@@ -169,11 +171,8 @@ export function useLiveQuery(configOrQueryOrCollection, deps = []) {
|
|
|
169
171
|
},
|
|
170
172
|
get data() {
|
|
171
173
|
const currentCollection = collection;
|
|
172
|
-
if (currentCollection) {
|
|
173
|
-
|
|
174
|
-
if (config.singleResult) {
|
|
175
|
-
return internalData[0];
|
|
176
|
-
}
|
|
174
|
+
if (currentCollection && isSingleResultCollection(currentCollection)) {
|
|
175
|
+
return internalData[0];
|
|
177
176
|
}
|
|
178
177
|
return internalData;
|
|
179
178
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/svelte-db",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.94",
|
|
4
4
|
"description": "Svelte integration for @tanstack/db",
|
|
5
5
|
"author": "Kyle Mathews",
|
|
6
6
|
"license": "MIT",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"skills"
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@tanstack/db": "0.6.
|
|
38
|
+
"@tanstack/db": "0.6.17"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"svelte": "^5.0.0"
|