make updatenodeinternal node id optional
This commit is contained in:
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
const onClick = () => {
|
const onClick = () => {
|
||||||
handleCount += 1;
|
handleCount += 1;
|
||||||
updateNodeInternals(id);
|
updateNodeInternals();
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import type { UpdateNodeInternals } from '@xyflow/system';
|
|
||||||
|
|
||||||
import { useStore } from '$lib/store';
|
import { useStore } from '$lib/store';
|
||||||
|
import { getContext } from 'svelte';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hook for updating node internals.
|
* Hook for updating node internals.
|
||||||
@@ -8,12 +7,16 @@ import { useStore } from '$lib/store';
|
|||||||
* @public
|
* @public
|
||||||
* @returns function for updating node internals
|
* @returns function for updating node internals
|
||||||
*/
|
*/
|
||||||
export function useUpdateNodeInternals(): UpdateNodeInternals {
|
export function useUpdateNodeInternals(): (nodeId?: string | string[]) => void {
|
||||||
const { domNode, updateNodeInternals } = $derived(useStore());
|
const { domNode, updateNodeInternals } = $derived(useStore());
|
||||||
|
const nodeId = getContext('svelteflow__node_id') as string | undefined;
|
||||||
|
|
||||||
// @todo: do we want to add this to system?
|
// @todo: do we want to add this to system?
|
||||||
const updateInternals = (id: string | string[]) => {
|
const updateInternals = (id?: string | string[]) => {
|
||||||
const updateIds = Array.isArray(id) ? id : [id];
|
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();
|
const updates = new Map();
|
||||||
|
|
||||||
updateIds.forEach((updateId) => {
|
updateIds.forEach((updateId) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user