fix: fixed the bug where repeatedly clicking on the currently edited application would cause the stateManager's store to be cleared

This commit is contained in:
xzdry 2022-05-12 09:51:48 +08:00
parent c03707ec41
commit e7a8b5954d
2 changed files with 9 additions and 3 deletions

View File

@ -58,7 +58,7 @@ export const StructureTree: React.FC<Props> = props => {
}, [selectedComponentId]);
return (
<VStack ref={wrapperRef} height='full' spacing="2" padding="4" alignItems="start" overflowWrap='break-word' overflowX='hidden' overflowY="auto">
<VStack ref={wrapperRef} height='full' spacing="2" padding="4" alignItems="start" overflowX='hidden' overflowY="auto">
<Text fontSize="lg" fontWeight="bold" mb="0.5rem">
Components
</Text>

View File

@ -17,6 +17,7 @@ import {
CORE_VERSION,
CoreComponentName,
} from '@sunmao-ui/shared';
import { isEqual } from 'lodash-es';
type EditingTarget = {
kind: 'app' | 'module';
@ -77,7 +78,12 @@ export class EditorStore {
// when switch app or module, components should refresh
reaction(
() => this.currentEditingTarget,
target => {
(target, prevTarget) => {
if (isEqual(prevTarget, target)) {
return;
}
if (target.name) {
this.setCurrentComponentsVersion(0);
this.setLastSavedComponentsVersion(0);
@ -175,7 +181,7 @@ export class EditorStore {
}
get activeDataSource(): ComponentSchema | null {
return this.components.find((component)=> component.id === this.activeDataSourceId) || null;
return this.components.find((component) => component.id === this.activeDataSourceId) || null;
}
get activeDataSourceType(): DataSourceType | null {