make updatenodeinternal node id optional

This commit is contained in:
peterkogo
2025-04-24 16:32:42 +02:00
parent c064954700
commit e47adb446f
2 changed files with 9 additions and 6 deletions

View File

@@ -9,7 +9,7 @@
const onClick = () => {
handleCount += 1;
updateNodeInternals(id);
updateNodeInternals();
};
</script>

View File

@@ -1,6 +1,5 @@
import type { UpdateNodeInternals } from '@xyflow/system';
import { useStore } from '$lib/store';
import { getContext } from 'svelte';
/**
* Hook for updating node internals.
@@ -8,12 +7,16 @@ import { useStore } from '$lib/store';
* @public
* @returns function for updating node internals
*/
export function useUpdateNodeInternals(): UpdateNodeInternals {
export function useUpdateNodeInternals(): (nodeId?: string | string[]) => void {
const { domNode, updateNodeInternals } = $derived(useStore());
const nodeId = getContext('svelteflow__node_id') as string | undefined;
// @todo: do we want to add this to system?
const updateInternals = (id: string | string[]) => {
const updateIds = Array.isArray(id) ? id : [id];
const updateInternals = (id?: string | string[]) => {
if (!id && !nodeId) {
throw new Error('When using outside of a node, you must provide an id.');
}
const updateIds = id ? (Array.isArray(id) ? id : [id]) : [nodeId];
const updates = new Map();
updateIds.forEach((updateId) => {