refactor(core): use empty arr when updating all internals (#1476)

* refactor(core): use empty arr when updating all internals

* chore(changeset): add
This commit is contained in:
Braks
2024-06-18 12:29:29 +02:00
parent 55a76cd9ad
commit cff55c8ebf
5 changed files with 10 additions and 10 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@vue-flow/core": minor
---
Use empty array when determing whether to update all node internals
@@ -153,7 +153,8 @@ const NodeWrapper = defineComponent({
const zIndex = toRef(() => Number(node.zIndex ?? getStyle.value.zIndex ?? 0)) const zIndex = toRef(() => Number(node.zIndex ?? getStyle.value.zIndex ?? 0))
onUpdateNodeInternals((updateIds) => { onUpdateNodeInternals((updateIds) => {
if (updateIds.includes(props.id)) { // when no ids are passed, update all nodes
if (updateIds.includes(props.id) || !updateIds.length) {
updateInternals() updateInternals()
} }
}) })
@@ -39,7 +39,6 @@ const initialViewportHelper: ViewportHelper = {
* *
* @internal * @internal
* @param state * @param state
* @param getters
*/ */
export function useViewportHelper(state: State) { export function useViewportHelper(state: State) {
function zoom(scale: number, duration?: number) { function zoom(scale: number, duration?: number) {
+2 -7
View File
@@ -53,16 +53,11 @@ import {
} from '../utils' } from '../utils'
import { storeOptionsToSkip, useState } from './state' import { storeOptionsToSkip, useState } from './state'
export function useActions( export function useActions(state: State, nodeLookup: ComputedRef<NodeLookup>, edgeLookup: ComputedRef<EdgeLookup>): Actions {
id: string,
state: State,
nodeLookup: ComputedRef<NodeLookup>,
edgeLookup: ComputedRef<EdgeLookup>,
): Actions {
const viewportHelper = useViewportHelper(state) const viewportHelper = useViewportHelper(state)
const updateNodeInternals: Actions['updateNodeInternals'] = (ids) => { const updateNodeInternals: Actions['updateNodeInternals'] = (ids) => {
const updateIds = ids ?? state.nodes.map((n) => n.id) ?? [] const updateIds = ids ?? []
state.hooks.updateNodeInternals.trigger(updateIds) state.hooks.updateNodeInternals.trigger(updateIds)
} }
+1 -1
View File
@@ -78,7 +78,7 @@ export class Storage {
const getters = useGetters(reactiveState, nodeLookup, edgeLookup) const getters = useGetters(reactiveState, nodeLookup, edgeLookup)
const actions = useActions(id, reactiveState, nodeLookup, edgeLookup) const actions = useActions(reactiveState, nodeLookup, edgeLookup)
actions.setState({ ...reactiveState, ...preloadedState }) actions.setState({ ...reactiveState, ...preloadedState })