Skip to content

Commit 47ac2a6

Browse files
committed
Allow any string value in meta
1 parent 317b8f5 commit 47ac2a6

File tree

4 files changed

+24
-9
lines changed

4 files changed

+24
-9
lines changed

.changeset/tasty-guests-cry.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@xstate/machine-extractor': minor
3+
---
4+
5+
Capture any string field from meta instead of just description
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { createMachine } from 'xstate';
2+
3+
export const machine = createMachine({
4+
meta: {
5+
description: 'description',
6+
someOtherField: 'hello there',
7+
},
8+
});
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import { StringLiteral, TemplateLiteral } from './scalars';
22
import { unionType } from './unionType';
3-
import { objectTypeWithKnownKeys } from './utils';
3+
import { objectOf } from './utils';
44

5-
export const MetaDescription = unionType([StringLiteral, TemplateLiteral]);
5+
export const MetaValues = unionType([StringLiteral, TemplateLiteral]);
66

7-
export const StateMeta = objectTypeWithKnownKeys({
8-
description: MetaDescription,
9-
});
7+
export const StateMeta = objectOf(MetaValues);

packages/machine-extractor/src/toMachineConfig.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,14 @@ const parseStateNode = (
101101
config.always = getTransitions(astResult.always, opts);
102102
}
103103

104-
if (astResult.meta?.description) {
105-
config.meta = {
106-
description: astResult.meta.description.value,
107-
};
104+
if (astResult.meta) {
105+
config.meta = astResult.meta.properties.reduce(
106+
(meta, props) => ({
107+
...meta,
108+
[props.key]: props.result.value,
109+
}),
110+
{},
111+
);
108112
}
109113

110114
if (astResult.onDone) {

0 commit comments

Comments
 (0)