mirror of
https://github.com/smartxworks/sunmao-ui.git
synced 2025-02-11 17:37:40 +08:00
Merge pull request #486 from webzard-io/fix/editor
fix: refreshing the StateView when switching between module and app
This commit is contained in:
commit
8a7028ce56
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user