designable icon indicating copy to clipboard operation
designable copied to clipboard

[Bug Report] InsertAfterEvent中不能及时拿到最新schema

Open NexxLuo opened this issue 4 years ago • 2 comments

场景: 监听schema变化,由于没有相关的onChange钩子,故用InsertAfterEvent这类事件代替。

 designer.subscribeTo(InsertAfterEvent, () => {
      let schema = transformToSchema(designer.getCurrentTree());
      console.log("InsertAfterEvent:", schema);
    });

问题: 在InsertAfterEvent无法拿到最新的schema,除非用setTimeOut添加延时获取

codesandbox: https://codesandbox.io/s/formily-designer-forked-j63w9c?file=/playground/main.tsx

NexxLuo avatar Mar 01 '22 09:03 NexxLuo

同求,如何拿到schame.json数据,除了点击右上{...}按钮的操作还有别的办法吗 InsertAfterEvent无法拿到最新的schema

767746649zyy avatar Jun 09 '22 01:06 767746649zyy

在 Workspace 下的组件里

import { autorun } from '@formily/reactive';
import {
  ...
  useTree,
} from '@designable/react';

...

const treeData = useTree('你的workspaceId');
useEffect(() => {
  return autorun(() => {
    const current = JSON.stringify(transformToSchema(treeData));
    onChange(current);
  });
}, [treeData, onChange]);

goxiaoy avatar Aug 09 '22 15:08 goxiaoy