Merge pull request #472 from webzard-io/fix/widget

refactor(trait): use `implementRuntimeTrait` to implement the transformer trait
This commit is contained in:
tanbowensg 2022-06-22 17:34:24 +08:00 committed by GitHub
commit f97b20555f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,20 +1,7 @@
import { createTrait } from '@sunmao-ui/core';
import { Static, Type } from '@sinclair/typebox';
import { TraitImplFactory } from '../../types';
import { Type } from '@sinclair/typebox';
import { implementRuntimeTrait } from '../../utils/buildKit';
import { CORE_VERSION, CoreTraitName } from '@sunmao-ui/shared';
const TransformTraitFactory: TraitImplFactory<
Static<typeof TransformerTraitPropertiesSpec>
> = () => {
return ({ value, mergeState }) => {
mergeState({ value });
return {
props: {},
};
};
};
const TransformerTraitPropertiesSpec = Type.Object({
value: Type.Any({
title: 'Value',
@ -24,18 +11,23 @@ const TransformerTraitStateSpec = Type.Object({
value: Type.Any(),
});
export default {
...createTrait({
version: CORE_VERSION,
metadata: {
name: CoreTraitName.Transformer,
description: 'transform the value',
},
spec: {
properties: TransformerTraitPropertiesSpec,
methods: [],
state: TransformerTraitStateSpec,
},
}),
factory: TransformTraitFactory,
};
export default implementRuntimeTrait({
version: CORE_VERSION,
metadata: {
name: CoreTraitName.Transformer,
description: 'transform the value',
},
spec: {
properties: TransformerTraitPropertiesSpec,
methods: [],
state: TransformerTraitStateSpec,
},
})(() => {
return ({ value, mergeState }) => {
mergeState({ value });
return {
props: {},
};
};
});