Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add description property to state and transition #2672

Merged
merged 1 commit into from Sep 20, 2021

Conversation

davidkpiano
Copy link
Member

@davidkpiano davidkpiano commented Sep 19, 2021

This PR adds description as a top-level property for state nodes and transitions:

const machine = createMachine({
  // ...
  states: {
    active: {
      // ...
      description: 'The task is in progress',
      on: {
        DEACTIVATE: {
          // ...
          description: 'Deactivates the task'
        }
      }
    }
  }
});

@changeset-bot
Copy link

changeset-bot bot commented Sep 19, 2021

⚠️ No Changeset found

Latest commit: 622565f

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@mattpocock
Copy link
Contributor

Is this an alternative to meta.description?. I like it.

@davidkpiano
Copy link
Member Author

davidkpiano commented Sep 19, 2021

Is this an alternative to meta.description?. I like it.

You got it! I feel that description merits its own property, especially as we're making statecharts-as-documentation first-class citizens.

@mattpocock
Copy link
Contributor

Agree! I will add this to the parser.

@Andarist
Copy link
Member

What the meta property is supposed to hold now? Is it just a bag of whatever one wants to put on a state/transition (basically Record<string, any>)? What has prompted moving this from the meta to the "core"?

@mattpocock
Copy link
Contributor

@Andarist Having autocomplete on description should be nice! And having it as a key on the event should also be handy

@@ -647,6 +648,10 @@ export interface StateNodeConfig<
* @default false
*/
preserveActionOrder?: boolean;
/**
* A description of the state node, rendered in Markdown
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably should mention here that "rendering in Markdown" applies to the XState visual tooling. It would also be nice to specify what flavor of Markdown this is interpreted as (I assume that it's GFM but could be Commonmark or something else)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the markdown part. Will specify in documentation for tooling, not here

@davidkpiano
Copy link
Member Author

What the meta property is supposed to hold now? Is it just a bag of whatever one wants to put on a state/transition (basically Record<string, any>)? What has prompted moving this from the meta to the "core"?

Devs use meta for many different things, some of which may even conflict with description etc. We ultimately don't want to mix things that XState will natively support in tooling (like description) with "free-form" meta objects.

Motivation is also here: #2672 (comment)

Copy link
Member

@Andarist Andarist left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably deserves a small changeset - other than that: LGTM

@davidkpiano davidkpiano merged commit 8e1d05d into main Sep 20, 2021
@davidkpiano davidkpiano deleted the davidkpiano/description branch September 20, 2021 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants