Skip to content

Commit 3ca9aca

Browse files
committed
docs: add section on changes
1 parent 63873ef commit 3ca9aca

File tree

3 files changed

+81
-6
lines changed

3 files changed

+81
-6
lines changed

docs/src/guide/controlled-flow.md

Lines changed: 73 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,83 @@ title: Controlled Flow
44

55
# Taking Control of Vue Flow
66

7-
Vue Flow is designed to be flexible and customizable, allowing you to take control of the flow of your application.
8-
By default, Vue Flow will apply changes automatically, so you don't have to worry about it.
9-
107
::: warning
11-
This API is subject to change in the next major release where changes will *most likely* not be applied automatically anymore.
8+
This API is subject to change in the next major release where changes will not be applied automatically anymore.
129
:::
1310

11+
By default, Vue Flow will apply *changes* automatically, so you don't have to worry about it.
12+
1413
Though, there are cases where you want to take control of changes and apply them manually after some processing and validations for example.
1514

16-
This guide will show you how to take control of Vue Flow and apply these changes manually.
15+
In this guide, we will learn how to take control of changes and apply them manually.
16+
17+
## What is a [Change](https://vueflow.dev/typedocs/types/NodeChange.html)?
18+
19+
A *change* is anything that is triggered by an interaction with the flow, like adding, updating (position, selected), or removing a node or an edge, either
20+
by dragging, clicking etc. or by using the provided API.
21+
22+
These changes are communicated to the user-land through the `onNodesChange` and `onEdgesChange` events.
23+
24+
Possible Changes include:
25+
26+
- [`add`](https://vueflow.dev/typedocs/interfaces/NodeAddChange.html): A node or an edge was added.
27+
- [`remove`](https://vueflow.dev/typedocs/interfaces/NodeRemoveChange.html): A node or an edge was removed.
28+
- [`select`](https://vueflow.dev/typedocs/interfaces/NodeSelectionChange.html): A node or an edge was selected/unselected.
29+
- [`position`](https://vueflow.dev/typedocs/interfaces/NodePositionChange.html): A nodes' position was updated.
30+
- [`dimensions`](https://vueflow.dev/typedocs/interfaces/NodeDimensionChange.html): A nodes' dimensions were updated.
31+
32+
::: warning
33+
Changes *do not* refer to *any* change in the flow, like zooming or panning, or just updating the `data` object of a node.
34+
:::
35+
36+
### Why is no change emitted when I update a node?
37+
38+
Vue Flow will not track your nodes/edges and try to figure out what changed, it will only emit changes when you interact with the flow or use the API.
39+
40+
For example this *will not* emit a change:
41+
42+
```vue
43+
<script setup>
44+
import { ref } from 'vue'
45+
46+
const nodes = ref([
47+
{
48+
id: '1',
49+
position: { x: 0, y: 0 },
50+
data: { label: 'Node 1' },
51+
},
52+
])
53+
54+
// this function *will not* emit a change
55+
function removeNode() {
56+
nodes.value = nodes.value.filter((node) => node.id !== '1')
57+
}
58+
</script>
59+
```
60+
61+
This is because Vue Flow does not know that the node with id `1` was removed, it only knows about changes that are triggered by the user or the API.
62+
63+
This, for example, *will* emit a change:
64+
65+
```vue
66+
<script setup>
67+
import { ref } from 'vue'
68+
import { useVueFlow } from '@vue-flow/core'
69+
70+
const nodes = ref([
71+
{
72+
id: '1',
73+
position: { x: 0, y: 0 },
74+
data: { label: 'Node 1' },
75+
},
76+
])
77+
78+
// this function *will* emit a change
79+
const { removeNodes } = useVueFlow()
80+
81+
removeNodes('1')
82+
</script>
83+
```
1784

1885
## The `applyChanges` option
1986

@@ -88,7 +155,7 @@ then use the `onNodesChange` event to listen to changes and validate delete chan
88155
if they are valid, use `applyNodeChanges` to apply them.
89156

90157
::: info
91-
Checkout the [confirm delete example](/examples/confirm).
158+
Checkout the [confirm delete example](/examples/confirm.html).
92159
:::
93160

94161
```vue

docs/src/guide/edge.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ For the full list of options available for an edge, check out the [Edge Type](/t
9292

9393
Edges are rendered by passing them to the `edges` prop (or the deprecated `v-model` prop) of the Vue Flow component.
9494

95+
:::warning
96+
This method will *not* create a change. Check out the [Controlled Flow](/guide/controlled-flow.html) section for more information.
97+
:::
98+
9599
:::code-group
96100

97101
```vue [<LogosJavascript />]

docs/src/guide/node.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ For the full list of options available for a node, check out the [Node Interface
6464

6565
Nodes are rendered by passing them to the `nodes` prop (or the deprecated `v-model` prop) of the Vue Flow component.
6666

67+
:::warning
68+
This method will *not* create a change. Check out the [Controlled Flow](/guide/controlled-flow.html) section for more information.
69+
:::
70+
6771
:::code-group
6872

6973
```vue [<LogosJavascript />]

0 commit comments

Comments
 (0)