Merge pull request #486 from webzard-io/fix/editor

fix: refreshing the StateView when switching between module and app
This commit is contained in:
tanbowensg 2022-07-04 15:11:12 +08:00 committed by GitHub
commit 8a7028ce56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 1 deletions

View File

@ -1,7 +1,7 @@
import { Editor as _Editor } from './components/Editor';
import { initSunmaoUI, SunmaoUIRuntimeProps } from '@sunmao-ui/runtime';
import { AppModelManager } from './operations/AppModelManager';
import React, { useState, useCallback } from 'react';
import React, { useState, useCallback, useEffect } from 'react';
import {
widgets as internalWidgets,
WidgetManager,
@ -110,6 +110,12 @@ export function initSunmaoUIEditor(props: SunmaoUIEditorProps = {}) {
});
}, []);
useEffect(() => {
eventBus.on('stateRefresh', onRefresh);
return () => {
eventBus.off('stateRefresh');
};
}, [onRefresh]);
return (
<ChakraProvider theme={editorTheme}>
<_Editor

View File

@ -89,6 +89,7 @@ export class EditorStore {
this.setCurrentComponentsVersion(0);
this.setLastSavedComponentsVersion(0);
this.clearSunmaoGlobalState();
this.eventBus.send('stateRefresh');
this.eventBus.send('componentsRefresh', this.originComponents);
this.setComponents(this.originComponents);

View File

@ -9,6 +9,7 @@ export type EventNames = {
// when switch app or module, current components refresh
componentsRefresh: ComponentSchema[];
// components change by operation
stateRefresh: undefined;
componentsChange: ComponentSchema[];
// it is only used for some operations' side effect
selectComponent: string;