Skip to content

Commit 02bec43

Browse files
Merge pull request #24 from viamrobotics/query-keys
Improve query keys
2 parents 1e5eb6b + 43d3ee6 commit 02bec43

9 files changed

+29
-3
lines changed

.changeset/shy-worlds-juggle.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@viamrobotics/svelte-sdk': patch
3+
---
4+
5+
Improve query keys

src/lib/hooks/create-resource-mutation.svelte.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export const createResourceMutation = <T extends Resource, K extends keyof T>(
1616

1717
const mutationOptions = $derived({
1818
mutationKey: [
19+
'viam-svelte-sdk',
1920
'partID',
2021
(client.current as T & { partID: string })?.partID,
2122
'resource',

src/lib/hooks/create-resource-query.svelte.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export const createResourceQuery = <T extends Resource, K extends keyof T>(
4848
const queryOptions = $derived(
4949
createQueryOptions({
5050
queryKey: [
51+
'viam-svelte-sdk',
5152
'partID',
5253
(client.current as T & { partID: string })?.partID,
5354
'resource',

src/lib/hooks/create-robot-mutation.svelte.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export const createRobotMutation = <T extends RobotClient, K extends keyof T>(
1616

1717
const mutationOptions = $derived({
1818
mutationKey: [
19+
'viam-svelte-sdk',
1920
'partID',
2021
(client.current as T & { partID: string })?.partID,
2122
'robotClient',

src/lib/hooks/create-robot-query.svelte.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export const createRobotQuery = <T extends RobotClient, K extends keyof T>(
4949
const queryOptions = $derived(
5050
createQueryOptions({
5151
queryKey: [
52+
'viam-svelte-sdk',
5253
'partID',
5354
(client.current as T & { partID: string })?.partID,
5455
'robotClient',

src/lib/hooks/create-stream-client.svelte.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export const createStreamClient = (
4242
const queryOptions = $derived(
4343
createQueryOptions({
4444
queryKey: [
45+
'viam-svelte-sdk',
4546
'partID',
4647
partID(),
4748
'resource',
@@ -62,6 +63,7 @@ export const createStreamClient = (
6263

6364
const mutationOptions = $derived({
6465
mutationKey: [
66+
'viam-svelte-sdk',
6567
'partID',
6668
partID(),
6769
'resource',

src/lib/hooks/machine-status.svelte.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@ export const provideMachineStatusContext = (refetchInterval: () => number) => {
2525
Object.entries(clients.current).map(([partID, client]) => {
2626
return queryOptions({
2727
enabled: client !== undefined,
28-
queryKey: ['partID', partID, 'robotClient', 'machineStatus'],
28+
queryKey: [
29+
'viam-svelte-sdk',
30+
'partID',
31+
partID,
32+
'robotClient',
33+
'machineStatus',
34+
],
2935
refetchInterval: refetchInterval(),
3036
queryFn: async (): Promise<MachineStatus> => {
3137
if (!client) {

src/lib/hooks/resource-names.svelte.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,14 @@ export const provideResourceNamesContext = () => {
3636

3737
return queryOptions({
3838
enabled: client !== undefined,
39-
queryKey: ['partID', partID, 'robotClient', 'resourceNames', revision],
39+
queryKey: [
40+
'viam-svelte-sdk',
41+
'partID',
42+
partID,
43+
'robotClient',
44+
'resourceNames',
45+
revision,
46+
],
4047
queryFn: async () => {
4148
if (!client) {
4249
throw new Error('No client');

src/lib/hooks/robot-clients.svelte.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ export const provideRobotClientsContext = (
5151

5252
await Promise.all([
5353
client?.disconnect(),
54-
queryClient.cancelQueries({ queryKey: ['partID', partID] }),
54+
queryClient.cancelQueries({
55+
queryKey: ['viam-svelte-sdk', 'partID', partID],
56+
}),
5557
]);
5658

5759
client.listeners['connectionstatechange']?.clear();

0 commit comments

Comments
 (0)