Add comments
This commit is contained in:
@@ -280,9 +280,14 @@ export function useReactFlow<NodeType extends Node = Node, EdgeType extends Edge
|
|||||||
?.values() ?? []
|
?.values() ?? []
|
||||||
),
|
),
|
||||||
fitView: async (options: FitViewOptions<NodeType> | undefined) => {
|
fitView: async (options: FitViewOptions<NodeType> | undefined) => {
|
||||||
|
// We either create a new Promise or reuse the existing one
|
||||||
|
// Even if fitView is called multiple times in a row, we only end up with a single Promise
|
||||||
const fitViewResolver = store.getState().fitViewResolver ?? Promise.withResolvers<boolean>();
|
const fitViewResolver = store.getState().fitViewResolver ?? Promise.withResolvers<boolean>();
|
||||||
|
|
||||||
|
// We schedule a fitView by setting fitViewQueued and triggering a setNodes
|
||||||
store.setState({ fitViewQueued: true, fitViewOptions: options, fitViewResolver });
|
store.setState({ fitViewQueued: true, fitViewOptions: options, fitViewResolver });
|
||||||
batchContext.nodeQueue.push((nodes) => [...nodes]);
|
batchContext.nodeQueue.push((nodes) => [...nodes]);
|
||||||
|
|
||||||
return fitViewResolver.promise;
|
return fitViewResolver.promise;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user