Skip to content

Commit

Permalink
feat: allow any string value in meta
Browse files Browse the repository at this point in the history
  • Loading branch information
abrgr committed Sep 29, 2022
1 parent 317b8f5 commit 609baff
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
8 changes: 8 additions & 0 deletions packages/machine-extractor/examples/meta.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { createMachine } from 'xstate';

export const machine = createMachine({
meta: {
description: 'description',
someOtherField: 'hello there',
},
});
8 changes: 3 additions & 5 deletions packages/machine-extractor/src/meta.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { StringLiteral, TemplateLiteral } from './scalars';
import { unionType } from './unionType';
import { objectTypeWithKnownKeys } from './utils';
import { objectOf } from './utils';

export const MetaDescription = unionType([StringLiteral, TemplateLiteral]);
export const MetaValues = unionType([StringLiteral, TemplateLiteral]);

export const StateMeta = objectTypeWithKnownKeys({
description: MetaDescription,
});
export const StateMeta = objectOf(MetaValues);
12 changes: 8 additions & 4 deletions packages/machine-extractor/src/toMachineConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,14 @@ const parseStateNode = (
config.always = getTransitions(astResult.always, opts);
}

if (astResult.meta?.description) {
config.meta = {
description: astResult.meta.description.value,
};
if (astResult.meta) {
config.meta = astResult.meta.properties.reduce(
(meta, props) => ({
...meta,
[props.key]: props.result.value,
}),
{},
);
}

if (astResult.onDone) {
Expand Down

0 comments on commit 609baff

Please sign in to comment.