@triplit/svelte 0.1.7 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +15 -0
- package/dist/index.svelte.d.ts +2 -1
- package/dist/index.svelte.js +16 -6
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,20 @@
|
|
1
1
|
# @triplit/svelte
|
2
2
|
|
3
|
+
## 0.1.9
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- 3d08941: add fetchingLocal state
|
8
|
+
- Updated dependencies [826acd1]
|
9
|
+
- Updated dependencies [3d08941]
|
10
|
+
- @triplit/client@0.3.37
|
11
|
+
|
12
|
+
## 0.1.8
|
13
|
+
|
14
|
+
### Patch Changes
|
15
|
+
|
16
|
+
- a74030c: fixup fetchingRemote
|
17
|
+
|
3
18
|
## 0.1.7
|
4
19
|
|
5
20
|
### Patch Changes
|
package/dist/index.svelte.d.ts
CHANGED
@@ -1,11 +1,12 @@
|
|
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;
|
7
8
|
updateQuery: (query: ClientQueryBuilder<M, CN>) => void;
|
8
9
|
};
|
9
10
|
export declare function useConnectionStatus(client: TriplitClient<any>): {
|
10
|
-
readonly status:
|
11
|
+
readonly status: string;
|
11
12
|
};
|
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
|
5
|
-
let
|
4
|
+
let isInitialFetch = $state(true);
|
5
|
+
let fetchingLocal = $state(false);
|
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
|
},
|
@@ -63,7 +73,7 @@ export function useQuery(client, query, options) {
|
|
63
73
|
};
|
64
74
|
}
|
65
75
|
export function useConnectionStatus(client) {
|
66
|
-
let status = $state(
|
76
|
+
let status = $state('CONNECTING');
|
67
77
|
$effect(() => {
|
68
78
|
const unsub = client.syncEngine.onConnectionStatusChange((newStatus) => {
|
69
79
|
status = newStatus;
|
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",
|