refactor(core): return promise from fromObject

This commit is contained in:
braks
2023-12-12 20:29:54 +01:00
committed by Braks
parent eb4cff30c9
commit c995b801ce
2 changed files with 29 additions and 21 deletions
+10 -2
View File
@@ -830,6 +830,7 @@ export function useActions(
}
const fromObject: Actions['fromObject'] = (obj) => {
return new Promise((resolve) => {
const { nodes, edges, position, zoom, viewport } = obj
if (nodes) {
@@ -845,16 +846,23 @@ export function useActions(
const y = viewport?.y || position[1]
const nextZoom = viewport?.zoom || zoom || state.viewport.zoom
until(() => viewportHelper.value.initialized)
return until(() => viewportHelper.value.initialized)
.toBe(true)
.then(() => {
viewportHelper.value.setViewport({
viewportHelper.value
.setViewport({
x,
y,
zoom: nextZoom,
})
.then(() => {
resolve(true)
})
})
} else {
resolve(true)
}
})
}
const $reset: Actions['$reset'] = () => {
+1 -1
View File
@@ -252,7 +252,7 @@ export interface Actions extends ViewportFunctions {
/** return an object of graph values (elements, viewport transform) for storage and re-loading a graph */
toObject: () => FlowExportObject
/** load graph from export obj */
fromObject: (obj: FlowExportObject) => void
fromObject: (obj: FlowExportObject) => Promise<boolean>
/** force update node internal data, if handle bounds are incorrect, you might want to use this */
updateNodeInternals: UpdateNodeInternals
/** start a connection */