fixed resetting nodes in svelte

This commit is contained in:
peterkogo
2024-02-28 17:42:33 +01:00
parent 966531ec39
commit 382cab728b
3 changed files with 64 additions and 7 deletions
@@ -23,7 +23,8 @@
'usenodesdata',
'usesvelteflow',
'useupdatenodeinternals',
'validation'
'validation',
'reset'
];
const onChange = (event: Event) => {
@@ -0,0 +1,43 @@
<script lang="ts">
import { writable } from 'svelte/store';
import {
SvelteFlow,
Controls,
Background,
MiniMap,
type Node,
type Edge,
type NodeTypes
} from '@xyflow/svelte';
import '@xyflow/svelte/dist/style.css';
const nodes = writable<Node[]>([]);
const edges = writable<Edge[]>([]);
const resetNodesArray = () => {
const node1: Node = {
id: 'c1',
data: { label: '1' },
position: { x: 0, y: 0 }
};
const node2: Node = {
id: 'c2',
data: { label: '2' },
position: { x: 100, y: 0 }
};
$nodes = [node1, node2];
};
</script>
<button on:click={resetNodesArray}> Reset </button>
<div style:height="100vh">
<SvelteFlow {nodes} {edges} fitView>
<Controls />
<Background />
<MiniMap />
</SvelteFlow>
</div>