Skip to content

Commit

Permalink
style: modify code style
Browse files Browse the repository at this point in the history
  • Loading branch information
mutu committed Jul 22, 2024
1 parent 1bba97c commit 9c732f0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
24 changes: 20 additions & 4 deletions packages/gi-sdk-app/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,29 @@ export interface StudioProps {
service: (id: string) => Promise<{ data: Project }>;
loadingText?: string;
loadingComponent?: React.ReactElement;
extraParams?: Record<string, any>;
GISDKExtraParams?: Record<string, any>;
componentExtraParams?: Record<string, any>;
}

const Studio: React.FunctionComponent<StudioProps> = props => {
// @ts-ignore
const { id, service, loadingText = '正在加载图应用...', loadingComponent, extraParams } = props;
const {
id,
service,
loadingText = '正在加载图应用...',
loadingComponent,
GISDKExtraParams,
componentExtraParams,
} = props;
const [state, setState] = React.useState({
isReady: false,
assets: null,
config: {},
services: [],
ThemeComponent: () => null,
GISDK: () => <></>,
extraParams: {},
GISDKExtraParams: {},
componentExtraParams: {},
});

const startStudio = async () => {
Expand Down Expand Up @@ -129,7 +138,14 @@ const Studio: React.FunctionComponent<StudioProps> = props => {
{/** @ts-ignore */}
<ThemeComponent style={{ visibility: 'hidden', position: 'absolute' }} />
{/** @ts-ignore */}
<GISDK config={config} assets={assets} services={services} id={`GI_STUDIO_${id}`} extraParams={extraParams} />
<GISDK
config={config}
assets={assets}
services={services}
id={`GI_STUDIO_${id}`}
GISDKExtraParams={GISDKExtraParams}
componentExtraParams={componentExtraParams}
/>
</>
);
};
Expand Down
11 changes: 5 additions & 6 deletions packages/gi-sdk/src/GISDK.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ let updateHistoryTimer: number;
const GISDK = (props: Props) => {
const graphinRef = React.useRef<null | Graphin>(null);
// @ts-ignore
const { children, assets, id, services, config, locales, extraParams = {} } = props;
const { children, assets, id, services, config, locales, componentExtraParams = {}, GISDKExtraParams = {} } = props;
const { language = 'zh-CN', ...localeMessages } = locales || {};
const GISDK_ID = React.useMemo(() => {
if (!id) {
Expand Down Expand Up @@ -62,7 +62,7 @@ const GISDK = (props: Props) => {
},
//@ts-ignore
GISDK_ID,
extraParams: {}
extraParams: {},
});

React.useEffect(() => {
Expand All @@ -74,9 +74,9 @@ const GISDK = (props: Props) => {
// 更新参数
React.useEffect(() => {
updateState(draft => {
draft.extraParams = props.extraParams?.GISDK;
draft.extraParams = GISDKExtraParams;
});
}, [props.extraParams]);
}, [GISDKExtraParams]);

const {
layout: layoutCfg,
Expand Down Expand Up @@ -368,9 +368,8 @@ const GISDK = (props: Props) => {
return null;
}

const { GISDK: GISDKExtraParams, ...componentExtraProps } = extraParams;
const { renderComponents, InitializerComponent, InitializerProps, GICC_LAYOUT_COMPONENT, GICC_LAYOUT_PROPS } =
getComponents({ ...state, HAS_GRAPH }, config.components, ComponentAssets, componentExtraProps);
getComponents({ ...state, HAS_GRAPH }, config.components, ComponentAssets, componentExtraParams);

const graphData = useMemo(() => {
const nodeMap = {};
Expand Down
6 changes: 4 additions & 2 deletions packages/gi-sdk/src/typing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,10 @@ export interface Props {
style?: React.CSSProperties;
className?: string;
children?: React.ReactChildren | JSX.Element | JSX.Element[];
/** 额外参数 */
extraParams?: Record<string, any>;
/** 全局额外参数 */
GISDKExtraParams?: Record<string, any>;
/** 资产额外参数,以资产ID为 key, value 为传入对应资产的 props */
componentExtraParams?: Record<string, any>;
}

export type AssetType =
Expand Down

0 comments on commit 9c732f0

Please sign in to comment.