Skip to content

Commit cd36279

Browse files
committed
fix(core): use separate prevConnections map
1 parent 6dbf1ea commit cd36279

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

packages/core/src/composables/useHandleConnections.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ export interface UseHandleConnectionsParams {
1313
onDisconnect?: (connections: Connection[]) => void
1414
}
1515

16+
// todo: add edge id to connection params
17+
1618
/**
1719
* Composable that returns existing connections of a handle
1820
*
@@ -39,6 +41,8 @@ export function useHandleConnections(params: UseHandleConnectionsParams): Comput
3941

4042
const handleId = toRef(() => toValue(id) ?? null)
4143

44+
const prevConnections = ref<Map<string, Connection> | null>(null)
45+
4246
const connections = ref<Map<string, Connection>>()
4347

4448
watch(
@@ -55,12 +59,14 @@ export function useHandleConnections(params: UseHandleConnectionsParams): Comput
5559

5660
watch(
5761
[connections, () => typeof onConnect !== 'undefined', () => typeof onDisconnect !== 'undefined'],
58-
([currentConnections], [prevConnections]) => {
59-
if (prevConnections && prevConnections !== currentConnections) {
62+
([currentConnections]) => {
63+
if (prevConnections.value && prevConnections.value !== currentConnections) {
6064
const _connections = currentConnections ?? new Map()
61-
handleConnectionChange(prevConnections, _connections, onDisconnect)
62-
handleConnectionChange(_connections, prevConnections, onConnect)
65+
handleConnectionChange(prevConnections.value, _connections, onDisconnect)
66+
handleConnectionChange(_connections, prevConnections.value, onConnect)
6367
}
68+
69+
prevConnections.value = currentConnections ?? new Map()
6470
},
6571
{ immediate: true },
6672
)

0 commit comments

Comments
 (0)