mirror of
https://github.com/smartxworks/sunmao-ui.git
synced 2025-04-06 21:40:23 +08:00
cancel trait side effect
This commit is contained in:
parent
161b3bf237
commit
35f33e0073
@ -126,12 +126,24 @@ export const ImplWrapper = React.forwardRef<
|
||||
}, [c.traits]);
|
||||
|
||||
// reduce traitResults
|
||||
const propsFromTraits: TraitResult = useMemo(() => {
|
||||
const propsFromTraits: TraitResult['props'] = useMemo(() => {
|
||||
return Array.from(traitResults.values()).reduce(
|
||||
(prevProps, result: TraitResult) => {
|
||||
return { ...prevProps, ...result.props };
|
||||
if (!result.props) {
|
||||
return prevProps;
|
||||
}
|
||||
|
||||
let effects = prevProps?.effects || [];
|
||||
if (result.props?.effects) {
|
||||
effects = effects?.concat(result.props?.effects);
|
||||
}
|
||||
return {
|
||||
...prevProps,
|
||||
...result.props,
|
||||
effects,
|
||||
};
|
||||
},
|
||||
{ props: null }
|
||||
{} as TraitResult['props']
|
||||
);
|
||||
}, [traitResults]);
|
||||
|
||||
|
@ -1,9 +1,16 @@
|
||||
import { createComponent } from '@meta-ui/core';
|
||||
import { useEffect } from 'react';
|
||||
import { ComponentImplementation } from 'src/registry';
|
||||
|
||||
const Dummy: ComponentImplementation<Record<string, unknown>> = ({
|
||||
effects,
|
||||
}) => {
|
||||
useEffect(() => {
|
||||
effects?.forEach(e => e());
|
||||
}, []);
|
||||
|
||||
const Dummy = () => {
|
||||
return null;
|
||||
};
|
||||
|
||||
export default {
|
||||
...createComponent({
|
||||
version: 'core/v1',
|
||||
|
@ -72,6 +72,7 @@ export type ComponentMergedProps = {
|
||||
style?: Record<string, any>;
|
||||
data?: Record<string, unknown>;
|
||||
callbackMap?: CallbackMap;
|
||||
effects?: Array<() => void>;
|
||||
app?: RuntimeApplication;
|
||||
};
|
||||
|
||||
@ -84,6 +85,7 @@ export type TraitResult = {
|
||||
data?: unknown;
|
||||
style?: Record<string, any>;
|
||||
callbackMap?: CallbackMap;
|
||||
effects?: Array<() => void>;
|
||||
} | null;
|
||||
};
|
||||
|
||||
|
@ -97,7 +97,13 @@ const useFetchTrait: TraitImplementation<Static<typeof PropsSchema>> = ({
|
||||
});
|
||||
|
||||
return {
|
||||
props: null,
|
||||
props: {
|
||||
effects: [
|
||||
() => {
|
||||
hasFetchedMap.set(hashId, false);
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user