From bea829efd607a96c3c1245e72307424892b8b004 Mon Sep 17 00:00:00 2001 From: lawvs <18554747+lawvs@users.noreply.github.com> Date: Wed, 27 Jul 2022 18:31:36 +0800 Subject: [PATCH] fix: view api --- libs/components/editor-core/src/recast-block/view.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/libs/components/editor-core/src/recast-block/view.ts b/libs/components/editor-core/src/recast-block/view.ts index 64f44eda7d..e26b38bb32 100644 --- a/libs/components/editor-core/src/recast-block/view.ts +++ b/libs/components/editor-core/src/recast-block/view.ts @@ -77,10 +77,9 @@ export const useRecastView = () => { const addView = useCallback( async (newView: RecastViewWithoutId) => { - await setViews([ - ...recastViews, - { ...newView, id: genViewId() } as RecastView, - ]); + const newViewWithId = { ...newView, id: genViewId() } as RecastView; + await setViews([...recastViews, newViewWithId]); + return newViewWithId; }, [recastViews, setViews] ); @@ -88,7 +87,7 @@ export const useRecastView = () => { const updateView = useCallback( async (newView: RecastView) => { const idx = recastViews.findIndex(v => v.id === newView.id); - if (!idx) { + if (idx === -1) { throw new Error('Failed to find view with id ' + newView.id); } await setViews([ @@ -141,7 +140,7 @@ export const useRecastView = () => { recastViews, setCurrentView, addView, - // updateView, + updateView, renameView, removeView, // TODO reorder API