Skip to content

Commit 47e988a

Browse files
committed
clone configs
1 parent 0f7fe40 commit 47e988a

File tree

4 files changed

+27
-10
lines changed

4 files changed

+27
-10
lines changed

.changeset/true-aliens-slide.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+
Clone previous configs for diffing

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,22 +65,21 @@ export const provideRobotClientsContext = (
6565
connectionStatus[partID] ??= MachineConnectionEvent.DISCONNECTED;
6666

6767
try {
68-
const dialConfig = { ...config };
69-
await disconnect(partID, dialConfig);
68+
await disconnect(partID, config);
7069

7170
connectionStatus[partID] = MachineConnectionEvent.CONNECTING;
7271

7372
// Reset the abort signal if it exists
74-
if (dialConfig.reconnectAbortSignal !== undefined) {
75-
dialConfig.reconnectAbortSignal = {
73+
if (config.reconnectAbortSignal !== undefined) {
74+
config.reconnectAbortSignal = {
7675
abort: false,
7776
};
7877
}
7978

80-
dialConfig.reconnectMaxAttempts ??= 1e9;
81-
dialConfig.reconnectMaxWait ??= 2000;
79+
config.reconnectMaxAttempts ??= 1e9;
80+
config.reconnectMaxWait ??= 2000;
8281

83-
const client = await createRobotClient(dialConfig);
82+
const client = await createRobotClient(config);
8483
(client as RobotClient & { partID: string }).partID = partID;
8584
client.on('connectionstatechange', (event) => {
8685
connectionStatus[partID] = (
@@ -104,6 +103,8 @@ export const provideRobotClientsContext = (
104103
Object.keys(lastConfigs)
105104
);
106105

106+
lastConfigs = structuredClone(configs);
107+
107108
for (const partID of removed) {
108109
disconnect(partID, lastConfigs[partID]);
109110
}
@@ -123,8 +124,6 @@ export const provideRobotClientsContext = (
123124
connect(partID, config);
124125
}
125126
}
126-
127-
lastConfigs = configs;
128127
});
129128

130129
onMount(() => {

src/routes/+layout.svelte

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,30 @@ import '../app.css';
33
import { SvelteQueryDevtools } from '@tanstack/svelte-query-devtools';
44
import { ViamProvider } from '$lib';
55
import type { Snippet } from 'svelte';
6-
import { dialConfigs as configs } from './configs';
6+
import { dialConfigs as c } from './configs';
77
import Parts from './components/parts.svelte';
8+
import type { DialConf } from '@viamrobotics/sdk';
89
910
interface Props {
1011
children: Snippet;
1112
}
1213
14+
let configs = $state.raw<Record<string, DialConf>>({});
15+
16+
const id = setInterval(() => {
17+
configs = structuredClone(c);
18+
}, 1000);
19+
20+
$effect.pre(() => {
21+
return () => clearTimeout(id);
22+
});
23+
1324
let enabled = $state<Record<string, boolean>>({});
1425
let dialConfigs = $derived(
1526
Object.fromEntries(Object.entries(configs).filter(([key]) => enabled[key]))
1627
);
1728
29+
$inspect(dialConfigs);
1830
let { children }: Props = $props();
1931
</script>
2032

src/routes/+layout.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export const prerender = true;
2+
export const ssr = false;

0 commit comments

Comments
 (0)