@viamrobotics/motion-tools 0.14.7 → 0.14.8

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.
@@ -4,24 +4,23 @@ import { getContext, setContext } from 'svelte';
4
4
  const key = Symbol('arm-client-context');
5
5
  export const provideArmClient = (partID) => {
6
6
  const arms = useResourceNames(partID, 'arm');
7
- const clients = $state({});
8
7
  const options = { refetchInterval: 500 };
9
- const jointPositionsQueries = $state({});
10
8
  const names = $derived(arms.current.map((arm) => arm.name));
11
- const currentPositions = $derived(Object.fromEntries(Object.entries(jointPositionsQueries).map(([name, query]) => [name, query.data?.values])));
12
- $effect(() => {
13
- for (const arm of arms.current) {
14
- const client = createResourceClient(ArmClient, partID, () => arm.name);
15
- if (client.current && !clients[arm.name])
16
- clients[arm.name] = { current: client.current };
17
- }
18
- });
19
- $effect(() => {
20
- for (const client of Object.values(clients)) {
9
+ const clients = $derived(arms.current.map((arm) => createResourceClient(ArmClient, partID, () => arm.name)));
10
+ const jointPositionsQueries = $derived.by(() => {
11
+ const results = {};
12
+ for (const client of clients) {
13
+ if (!client.current)
14
+ continue;
21
15
  const query = createResourceQuery(client, 'getJointPositions', options);
22
- jointPositionsQueries[client.current.name] = query.current;
16
+ results[client.current.name] = query;
23
17
  }
18
+ return results;
24
19
  });
20
+ const currentPositions = $derived(Object.fromEntries(Object.entries(jointPositionsQueries).map(([name, query]) => [
21
+ name,
22
+ query.current.data?.values,
23
+ ])));
25
24
  setContext(key, {
26
25
  get names() {
27
26
  return names;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@viamrobotics/motion-tools",
3
- "version": "0.14.7",
3
+ "version": "0.14.8",
4
4
  "description": "Motion visualization with Viam",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",