make updatenodeinternal node id optional
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
|
||||
const onClick = () => {
|
||||
handleCount += 1;
|
||||
updateNodeInternals(id);
|
||||
updateNodeInternals();
|
||||
};
|
||||
</script>
|
||||
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user