@triplit/svelte 0.1.8 → 0.1.9
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/CHANGELOG.md +9 -0
- package/dist/index.svelte.d.ts +1 -0
- package/dist/index.svelte.js +14 -4
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
package/dist/index.svelte.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ClientFetchResult, ClientQuery, ClientQueryBuilder, CollectionNameFromModels, Models, SubscriptionOptions, TriplitClient } from '@triplit/client';
|
|
2
2
|
export declare function useQuery<M extends Models<any, any> | undefined, CN extends CollectionNameFromModels<M>>(client: TriplitClient<any>, query: ClientQueryBuilder<M, CN>, options?: Partial<SubscriptionOptions>): {
|
|
3
3
|
fetching: boolean;
|
|
4
|
+
fetchingLocal: boolean;
|
|
4
5
|
fetchingRemote: boolean;
|
|
5
6
|
results: ClientFetchResult<ClientQuery<M, CN>> | undefined;
|
|
6
7
|
error: any;
|
package/dist/index.svelte.js
CHANGED
|
@@ -1,18 +1,25 @@
|
|
|
1
1
|
/// <reference types="svelte" />
|
|
2
2
|
export function useQuery(client, query, options) {
|
|
3
3
|
let results = $state(undefined);
|
|
4
|
-
let
|
|
4
|
+
let isInitialFetch = $state(true);
|
|
5
|
+
let fetchingLocal = $state(false);
|
|
5
6
|
let fetchingRemote = $state(client.syncEngine.connectionStatus !== 'CLOSED');
|
|
7
|
+
let fetching = $derived(isInitialFetch && fetchingRemote);
|
|
6
8
|
let error = $state(undefined);
|
|
7
9
|
let hasResponseFromServer = false;
|
|
8
10
|
let builtQuery = $state(query && query.build());
|
|
9
11
|
function updateQuery(query) {
|
|
10
12
|
builtQuery = query.build();
|
|
11
13
|
results = undefined;
|
|
12
|
-
|
|
14
|
+
fetchingLocal = true;
|
|
13
15
|
hasResponseFromServer = false;
|
|
14
16
|
}
|
|
15
17
|
$effect(() => {
|
|
18
|
+
client.syncEngine
|
|
19
|
+
.isFirstTimeFetchingQuery(builtQuery)
|
|
20
|
+
.then((isFirstFetch) => {
|
|
21
|
+
isInitialFetch = isFirstFetch;
|
|
22
|
+
});
|
|
16
23
|
const unsub = client.syncEngine.onConnectionStatusChange((status) => {
|
|
17
24
|
if (status === 'CLOSING' || status === 'CLOSED') {
|
|
18
25
|
fetchingRemote = false;
|
|
@@ -29,11 +36,11 @@ export function useQuery(client, query, options) {
|
|
|
29
36
|
});
|
|
30
37
|
$effect(() => {
|
|
31
38
|
const unsubscribe = client.subscribe(builtQuery, (localResults) => {
|
|
32
|
-
|
|
39
|
+
fetchingLocal = false;
|
|
33
40
|
error = undefined;
|
|
34
41
|
results = new Map(localResults);
|
|
35
42
|
}, (error) => {
|
|
36
|
-
|
|
43
|
+
fetchingLocal = false;
|
|
37
44
|
error = error;
|
|
38
45
|
}, {
|
|
39
46
|
...(options ?? {}),
|
|
@@ -50,6 +57,9 @@ export function useQuery(client, query, options) {
|
|
|
50
57
|
get fetching() {
|
|
51
58
|
return fetching;
|
|
52
59
|
},
|
|
60
|
+
get fetchingLocal() {
|
|
61
|
+
return fetchingLocal;
|
|
62
|
+
},
|
|
53
63
|
get fetchingRemote() {
|
|
54
64
|
return fetchingRemote;
|
|
55
65
|
},
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@triplit/svelte",
|
|
3
3
|
"packageManager": "yarn@3.4.1",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.9",
|
|
5
5
|
"source": "./src/index.svelte.ts",
|
|
6
6
|
"main": "./dist/index.svelte.js",
|
|
7
7
|
"module": "./dist/index.svelte.js",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"/dist"
|
|
28
28
|
],
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@triplit/client": "^0.3.
|
|
30
|
+
"@triplit/client": "^0.3.37"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@sveltejs/package": "^2.3.0",
|