├── .eslintrc.json
├── .github
└── workflows
│ └── main.yml
├── .gitignore
├── .prettierrc
├── .vscode
└── settings.json
├── .yarnrc.yml
├── README.md
├── content
├── metadata.ts
└── posts
│ ├── 2019-11-13-no-disabling-a-button-is-not-app-logic.mdx
│ ├── 2019-12-09-xstate-version-47-and-the-future.mdx
│ ├── 2020-01-20-redux-is-half-a-pattern-1-2.mdx
│ ├── 2020-05-22-redux-is-half-a-pattern-2-2.mdx
│ ├── 2020-05-27-state-management-bad-bolean-good-boolean.mdx
│ ├── 2020-07-27-state-machines-how-to-stop-making-horcruxes-in-your-code.mdx
│ ├── 2021-01-11-just-use-props-an-opinionated-guide-to-react-and-xstate.mdx
│ ├── 2021-01-20-you-dont-need-a-library-for-state-machines.mdx
│ ├── 2021-04-28-whats-the-difference-between-machine-and-createmachine.mdx
│ ├── 2021-04-29-should-this-be-a-state-or-in-context.mdx
│ ├── 2021-04-30-should-this-be-an-action-or-a-service.mdx
│ ├── 2021-05-13-why-i-love-invoked-callbacks.mdx
│ ├── 2021-05-27-global-state-xstate-react.mdx
│ ├── 2021-07-28-usestate-vs-usereducer-vs-xstate-part-1-modals.mdx
│ ├── 2021-10-02-intro-fsm-sc.mdx
│ ├── 2021-10-11-convince-teammates.mdx
│ ├── 2021-12-14-what-are-the-biggest-benefits-youve-had-from-using-state-machines.mdx
│ ├── 2022-01-27-introducing-typegen.mdx
│ ├── 2022-02-14-modelling-101-how-to-build-a-statechart-from-scratch.mdx
│ ├── 2022-03-03-introducing-the-xstate-cli.mdx
│ ├── 2022-03-11-xstate-vscode-extension-now-available-on-the-open-vsx-registry.mdx
│ ├── 2022-03-15-introducing-the-new-stately-homepage.mdx
│ ├── 2022-03-23-stately-changelog-1.mdx
│ ├── 2022-03-28-stately-is-hiring.mdx
│ ├── 2022-03-29-introducing-the-new-stately-roadmap.mdx
│ ├── 2022-04-05-building-a-video-player.mdx
│ ├── 2022-05-03-whats-new-may-2022.mdx
│ ├── 2022-06-07-whats-new-june-2022.mdx
│ ├── 2022-06-13-nesting-typegen-files.mdx
│ ├── 2022-06-20-what-is-xstate-used-for.mdx
│ ├── 2022-07-06-whats-new-july-2022.mdx
│ ├── 2022-07-18-just-use-hooks-xstate-in-react-components.mdx
│ ├── 2022-08-03-whats-new-august-2022.mdx
│ ├── 2022-08-10-get-started-with-xstate-using-xsm-snippet.mdx
│ ├── 2022-08-17-goodbye-use-effect-at-react-next.mdx
│ ├── 2022-08-23-building-a-resizable-panel.mdx
│ ├── 2022-08-31-building-a-resizable-panel.mdx
│ ├── 2022-09-14-whats-new-september-2022.mdx
│ ├── 2022-10-18-stately-studio-1-0.mdx
│ ├── 2022-10-27-studio-tutorials.mdx
│ ├── 2022-11-22-studio-update.mdx
│ ├── 2022-11-29-import-from-code.mdx
│ ├── 2022-12-13-new-in-the-studio-machine-disaster-recovery.mdx
│ ├── 2022-2-6-stately-editor-public-beta.mdx
│ ├── 2023-01-19-introducing-the-stately-docs.mdx
│ ├── 2023-01-20-whats-new-in-2023.mdx
│ ├── 2023-02-06-github-import-machines.mdx
│ ├── 2023-03-09-import-all-machines-from-github-repo.mdx
│ ├── 2023-04-03-book-a-demo.mdx
│ ├── 2023-05-02-track-changes-as-you-work-with-version-history.mdx
│ ├── 2023-05-03-introducing-state-new.mdx
│ ├── 2023-05-04-everything-new-since-stately-studio-1-0.mdx
│ ├── 2023-05-12-office-hours-64.mdx
│ ├── 2023-05-16-stately-streams.mdx
│ ├── 2023-05-18-explain-your-machines-with-annotations.mdx
│ ├── 2023-05-25-announcing-xstate-v5-beta.mdx
│ └── 2023-1-27-making-state-machines-global-in-react.mdx
├── jest.config.js
├── lib
├── create-new-post.ts
├── edit-post.ts
└── utils.ts
├── next-env.d.ts
├── next.config.js
├── package.json
├── pages
├── 404.tsx
├── [slug].tsx
├── _app.tsx
├── _document.tsx
└── index.tsx
├── patches
├── @jsdevtools+rehype-toc+3.0.2.patch
└── prompts+2.4.2.patch
├── public
├── 2019-11-13-no-disabling-a-button-is-not-app-logic.png
├── 2019-12-09-xstate-version-47-and-the-future.png
├── 2020-01-20-redux-is-half-a-pattern-1-2.png
├── 2020-05-22-redux-is-half-a-pattern-2-2.png
├── 2020-05-27-state-management-bad-bolean-good-boolean.png
├── 2020-07-27-state-machines-how-to-stop-making-horcruxes-in-your-code.png
├── 2021-01-11-just-use-props-an-opinionated-guide-to-react-and-xstate.png
├── 2021-01-20-you-dont-need-a-library-for-state-machines.png
├── 2021-04-28-whats-the-difference-between-machine-and-createmachine.png
├── 2021-04-29-should-this-be-a-state-or-in-context.png
├── 2021-04-30-should-this-be-an-action-or-a-service.png
├── 2021-05-13-why-i-love-invoked-callbacks.png
├── 2021-05-27-global-state-xstate-react.png
├── 2021-07-28-usestate-vs-usereducer-vs-xstate-part-1-modals.png
├── 2021-10-02-intro-fsm-sc.png
├── 2021-10-11-convince-teammates.png
├── 2021-12-14-what-are-the-biggest-benefits-youve-had-from-using-state-machines.png
├── 2022-01-27-introducing-typegen.png
├── 2022-02-08-join-the-stately-editor-public-beta.png
├── 2022-02-15-modelling-101-how-to-build-a-statechart-from-scratch.png
├── 2022-03-03-introducing-the-xstate-cli.png
├── 2022-03-15-xstate-vscode-extension-now-available-on-the-open-vsx-registry.png
├── 2022-03-16-introducing-the-new-stately-homepage.png
├── 2022-03-23-stately-changelog-1.png
├── 2022-03-28-stately-is-hiring.png
├── 2022-03-29-introducing-the-roadmap.png
├── 2022-04-05-building-a-video-player.png
├── 2022-05-03-whats-new-may-2022.png
├── 2022-06-07-whats-new-june-2022.png
├── 2022-06-13-nesting-typegen-files.png
├── 2022-06-21-what-is-xstate-used-for.png
├── 2022-07-06-canny.png
├── 2022-07-06-labeled-buttons.png
├── 2022-07-06-search.png
├── 2022-07-06-whats-new-july-2022.png
├── 2022-07-18-just-use-hooks-xstate-in-react-components.png
├── 2022-07-18-useMachine-hook-example.png
├── 2022-08-03-whats-new-august-2022.png
├── 2022-08-10-get-started-with-xstate-using-xsm-snippet.png
├── 2022-08-17-goodbye-use-effect-at-react-next.png
├── 2022-08-22-building-a-resizable-panel.png
├── 2022-08-31-building-a-resizable-panel.png
├── 2022-09-14-whats-new-september-2022.png
├── 2022-10-18-introducing-stately-studio-1-0.png
├── 2022-10-27-studio-tutorials.png
├── 2022-11-22-studio-update-highlighted-selected-event.png
├── 2022-11-22-studio-update-login-providers.png
├── 2022-11-22-studio-update.png
├── 2022-11-29-import-from-code-create-machine.png
├── 2022-11-29-import-from-code-importer.png
├── 2022-11-29-import-from-code-left-drawer.png
├── 2022-11-29-import-from-code-right-panel.png
├── 2022-11-29-import-from-code.png
├── 2022-12-22-machine-recovery.png
├── 2023-01-19-docs-contribute.png
├── 2023-01-19-docs-light-mode.png
├── 2023-01-19-docs-search.png
├── 2023-01-19-docs-xstate.png
├── 2023-01-19-docs.png
├── 2023-01-19-introducing-the-stately-docs.png
├── 2023-01-20-machine-images.png
├── 2023-01-20-read-only.png
├── 2023-01-20-stately-streams.png
├── 2023-01-20-team-in-lisbon.png
├── 2023-01-20-whats-new-in-2023.png
├── 2023-01-20-xstate-vscode.png
├── 2023-02-06-github-import-machines.png
├── 2023-03-09-import-all-machines-from-github-repo.png
├── 2023-04-03-book-a-demo.png
├── 2023-05-02-version-history.png
├── 2023-05-03-introducing-state-new.png
├── 2023-05-04-everything-new-since-stately-studio-1-0.png
├── 2023-05-04-import-from-code.png
├── 2023-05-04-tutorials.png
├── 2023-05-04-version-history.png
├── 2023-05-12-office-hours-64.png
├── 2023-05-16-stately-streams.png
├── 2023-05-18-explain-your-machines-with-annotations.png
├── 2023-05-25-announcing-xstate-v5-beta.png
├── 2023-1-27-making-state-machines-global-in-react.png
├── apple-touch-icon.png
├── august-22-editor-improvements.png
├── changelog-1-events.png
├── context-menu-demo.mp4
├── favicon.ico
├── fonts
│ └── ttcommons.woff2
├── human-readable-timers.png
├── icon-192.png
├── icon-512.png
├── icon.svg
├── images
│ ├── 2023-03-09-import-all-machines-from-github-repo-button.png
│ ├── 2023-05-02-example-restore-from-version-list.png
│ ├── 2023-05-02-example-version-view-explained.png
│ ├── 2023-05-02-example-version-view-plain.png
│ ├── 2023-05-02-example-why-audiences.png
│ ├── 2023-05-02-example-why-layers-of-detail.png
│ ├── 2023-05-02-example-why-modeling-experiments.png
│ ├── dark-mode.png
│ ├── github-import-machine.gif
│ ├── github-install-integration.gif
│ ├── github-save-machine.gif
│ ├── light-mode.png
│ ├── recovery_offline_error.gif
│ ├── recovery_restore_machine.gif
│ ├── state.new-starter-diagram.png
│ ├── stately-editor-public-beta.png
│ ├── studio_architecture_challenges.png
│ ├── with-typegen.gif
│ ├── without-typegen.png
│ └── xstate-vscode-settings.png
├── manifest.webmanifest
├── og-image.png
├── select-all-keyboard-shortcut.gif
├── snap-to-elements.mp4
├── studio-1-0-editor.png
├── studio-1-0-export.png
├── studio-1-0-guards.png
├── studio-1-0-projects.png
├── studio-1-0-simulate.png
├── studio-1-0-teams.png
├── studio-1-0-upgrade.png
├── studio-1-0-visibility.png
├── vercel.svg
├── vscode-darkmode.png
├── vscode-lightmode.png
├── writing-guide-viz-image.png
└── xsm-snippet.gif
├── src
├── MetadataContext.tsx
├── PostsContext.tsx
├── Seo.tsx
├── __tests__
│ └── utils.test.ts
├── components
│ ├── Announcement.tsx
│ ├── Layout.tsx
│ ├── Logo.tsx
│ ├── MDXComponents.tsx
│ ├── PageFooter.tsx
│ ├── PageHeader.tsx
│ ├── Sidebar.tsx
│ └── Viz.tsx
├── feed.tsx
├── posts.ts
├── serializePost.ts
├── theme.ts
├── types.ts
└── utils.ts
├── styles
├── globals.scss
├── highlight.css
├── nprogress.css
└── post.scss
├── tsconfig.json
└── yarn.lock
/.eslintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "next/core-web-vitals"
3 | }
4 |
--------------------------------------------------------------------------------
/.github/workflows/main.yml:
--------------------------------------------------------------------------------
1 | name: CI/CD
2 |
3 | on: [push]
4 |
5 | jobs:
6 | verifying-project:
7 | runs-on: ubuntu-latest
8 |
9 | steps:
10 | - name: Checkout
11 | uses: actions/checkout@v3
12 |
13 | - name: Setup Node 16
14 | uses: actions/setup-node@v3
15 | with:
16 | node-version: 16.x
17 |
18 | - name: Lint
19 | run: yarn && yarn lint && yarn tsc
20 |
21 | - name: Build
22 | run: yarn next build
23 | env:
24 | CI: "false"
25 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 |
8 | # testing
9 | /coverage
10 |
11 | # next.js
12 | /.next/
13 | /out/
14 |
15 | # production
16 | /build
17 |
18 | # misc
19 | .DS_Store
20 | *.pem
21 |
22 | # debug
23 | npm-debug.log*
24 | yarn-debug.log*
25 | yarn-error.log*
26 |
27 | # local env files
28 | .env.local
29 | .env.development.local
30 | .env.test.local
31 | .env.production.local
32 |
33 | # vercel
34 | .vercel
35 |
36 | # cli
37 | lib/*.js
38 |
39 | # feed
40 | public/feeds
41 | .yarn
42 |
--------------------------------------------------------------------------------
/.prettierrc:
--------------------------------------------------------------------------------
1 | {}
2 |
--------------------------------------------------------------------------------
/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "typescript.tsdk": "node_modules/typescript/lib",
3 | "[mdx]": {
4 | "editor.wordWrap": "on"
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/.yarnrc.yml:
--------------------------------------------------------------------------------
1 | nodeLinker: node-modules
2 |
--------------------------------------------------------------------------------
/content/metadata.ts:
--------------------------------------------------------------------------------
1 | import { MetadataOverrides } from "../src/types";
2 |
3 | export const DEFAULT_TITLE = "Stately Blog";
4 | export const DEFAULT_DESCRIPTION = "The official blog of Stately.ai";
5 | export const DEFAULT_URL = "https://stately.ai/blog";
6 | export const DEFAULT_OG_IMAGE = {
7 | url: "https://stately.ai/blog/og-image.png", // needs to be absolute URL
8 | width: 0,
9 | height: 0,
10 | alt: DEFAULT_TITLE,
11 | type: "image/png", // change based on actual OG image type
12 | };
13 |
14 | export const AUTHORS = [
15 | { name: "Farzad Yousefzadeh", twitterHandle: "@farzad_yz" },
16 | { name: "Laura Kalbag", twitterHandle: "@lauraKalbag" },
17 | { name: "Matt Pocock", twitterHandle: "@mpocock1" },
18 | { name: "David K. 🎹", twitterHandle: "@DavidKPiano" },
19 | { name: "Andarist", twitterHandle: "@AndaristRake" },
20 | { name: "Jenny Truong", twitterHandle: "@jen_ayy_" },
21 | { name: "Anders Bech Mellson", twitterHandle: "@andersmellson" },
22 | ] as const;
23 |
24 | export const makeMetadata = ({
25 | title = DEFAULT_TITLE,
26 | description = DEFAULT_DESCRIPTION,
27 | url = DEFAULT_URL,
28 | originalURL,
29 | article,
30 | ogImage = DEFAULT_OG_IMAGE.url,
31 | }: MetadataOverrides | undefined = {}) => ({
32 | title,
33 | description,
34 | authors: AUTHORS,
35 | canonical: originalURL || undefined,
36 | openGraph: {
37 | url,
38 | title,
39 | description,
40 | type: article ? "article" : "website",
41 | locale: "en_US",
42 | site_name: DEFAULT_TITLE,
43 | images: [
44 | {
45 | url: ogImage, // needs to be absolute URL
46 | width: 0,
47 | height: 0,
48 | alt: `‘${title}’ by ${article?.authors![0]} on the Stately Blog.`, // TODO: multiple authors
49 | type: "image/png",
50 | },
51 | ],
52 | article,
53 | },
54 | twitter: {
55 | handle: "@statelyai",
56 | site: "@statelyai",
57 | cardType: "summary_large_image",
58 | creator: article?.authors?.[0],
59 | },
60 | });
61 |
--------------------------------------------------------------------------------
/content/posts/2020-05-27-state-management-bad-bolean-good-boolean.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: "State Management: How to tell a bad boolean from a good boolean"
3 | description: "TL;DR: Bad booleans represent state. Good booleans are derived from state"
4 | tags:
5 | - tutorial
6 | author: Matt Pocock
7 | category: entry
8 | publishedAt: "2020-05-27"
9 | ogImage: "https://stately.ai/blog/2020-05-27-state-management-bad-bolean-good-boolean.png"
10 | ---
11 |
12 | **TL;DR**: Bad booleans represent state. Good booleans are derived from state.
13 |
14 | When you’re managing state in your app, it’s easy to fall prey to bad booleans. Bad booleans look like this:
15 |
16 | ```js
17 | let isLoading = true;
18 | let isComplete = false;
19 | let hasErrored = false;
20 | ```
21 |
22 | On the surface, this looks like good code. It appears as though you’ve represented three separate states with proper boolean names. In the ‘model’ you’ve pictured for your state, only one of these states can be true at any one time.
23 |
24 | In a fetch request, you might model the state like this:
25 |
26 | ```js
27 | const makeFetch = async () => {
28 | isLoading = true;
29 | try {
30 | await fetch("/users");
31 |
32 | isComplete = true;
33 | } catch (e) {
34 | hasErrored = true;
35 | }
36 | isLoading = false;
37 | };
38 | ```
39 |
40 | Again, this looks nice. We’re orchestrating our booleans as we move through the async request.
41 |
42 | But there’s a bug here. What happens if we make the fetch, it succeeds, and we make the fetch again? We’ll end up with:
43 |
44 | ```js
45 | let isLoading = true;
46 | let isComplete = true;
47 | let hasErrored = false;
48 | ```
49 |
50 | ## Implicit states
51 |
52 | You probably hadn’t considered this when you made your initial model. You may have frontend components which are checking for `isComplete === ` true or `isLoading === true`. You might end up with a loading spinner and the previous data showing at the same time.
53 |
54 | How is this possible? Well, you’ve created some implicit states. Let’s imagine you considered 3 states as ones you actually wanted to handle:
55 |
56 | 1. `loading`: Loading the data
57 | 2. `complete`: Showing the data
58 | 3. `errored`: Erroring if the data doesn't turn up
59 |
60 | Well, you’ve actually allowed 8 states! That’s 2 for the first boolean, times 2 for the second, times 2 for the third.
61 |
62 | This is what's known as boolean explosion - I learned about this from [Kyle Shevlin's egghead course](https://egghead.io/lessons/javascript-eliminate-boolean-explosion-by-enumerating-states).
63 |
64 | ## Making states explicit
65 |
66 | How do you get around this? Instead of a system with 8 possible values, we need a system with three possible values. We can do this in Typescript with an enum.
67 |
68 | ```ts
69 | type Status = "loading" | "complete" | "errored";
70 |
71 | let status: Status = "loading";
72 | ```
73 |
74 | We’d implement this in a fetch like this:
75 |
76 | ```ts
77 | const makeFetch = async () => {
78 | status = "loading";
79 | try {
80 | await fetch("/users");
81 |
82 | status = "complete";
83 | } catch (e) {
84 | status = "errored";
85 | }
86 | };
87 | ```
88 |
89 | It’s now impossible to be in the 'loading' and 'complete' state at once - we’ve fixed our bug. We’ve turned our bad booleans into a good enum.
90 |
91 | ## Making good booleans
92 |
93 | But not all booleans are bad. Many popular libraries, such as _react-query_, _apollo_ and _urql_ use booleans in their state. An example implementation:
94 |
95 | ```js
96 | const [result] = useQuery();
97 |
98 | if (result.isLoading) {
99 | return
Loading...
;
100 | }
101 | ```
102 |
103 | The reason these are good booleans is that their underlying mechanism is based on an enum. Bad booleans represent state. Good booleans are derived from state:
104 |
105 | ```js
106 | let status: Status = "loading";
107 |
108 | // Derived from the status above
109 | let isLoading = status === "loading";
110 | ```
111 |
112 | You can safely use this `isLoading` to display your loading spinner, happy in the knowledge that you've removed all impossible states.
113 |
114 | ## Addendum: Enums in Javascript
115 |
116 | We can represent a state enum in Javascript as well. While the above code will work without typings, you can represent enums as an object type.
117 |
118 | ```ts
119 | const statusEnum = {
120 | loading: "loading",
121 | complete: "complete",
122 | errored: "errored",
123 | };
124 |
125 | let status = statusEnum.loading;
126 |
127 | const makeFetch = async () => {
128 | status = statusEnum.loading;
129 | try {
130 | await fetch("/users");
131 |
132 | status = statusEnum.complete;
133 | } catch (e) {
134 | status = statusEnum.errored;
135 | }
136 | };
137 | ```
138 |
--------------------------------------------------------------------------------
/content/posts/2021-04-28-whats-the-difference-between-machine-and-createmachine.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: What’s the difference between Machine and createMachine?
3 | description: >-
4 | XState offers two options for declaring machine definitions. This can be
5 | confusing for beginners. Why are there two very similar-looking methods?
6 | What’s the difference?
7 | tags:
8 | - typescript
9 | - state machine
10 | author: Matt Pocock
11 | excerpt: ""
12 | publishedAt: "2021-04-28"
13 | originalURL: "https://dev.to/mpocock1/xstate-what-s-the-difference-between-machine-and-createmachine-15h1"
14 | ogImage: "https://stately.ai/blog/2021-04-28-whats-the-difference-between-machine-and-createmachine.png"
15 | ---
16 |
17 | XState offers two options for declaring machine definitions:
18 |
19 | ```ts
20 | import { Machine } from "xstate";
21 |
22 | const machine = Machine({ ...config });
23 | ```
24 |
25 | …or…
26 |
27 | ```ts
28 | import { createMachine } from "xstate";
29 |
30 | const machine = createMachine({ ...config });
31 | ```
32 |
33 | This can be confusing for beginners. Why are there two very similar-looking methods? What’s the difference?
34 |
35 | ## The Difference
36 |
37 | In Javascript, there is no difference between the two. You can use them completely interchangeably.
38 |
39 | In Typescript, there is only a small difference between them - it’s to do with the ordering of the generics you can pass to the machine. `Machine` allows you to pass a generic called ['Typestates'](https://xstate.js.org/docs/guides/typescript.html#typestates) in the middle of the `Context` and `Event` generics.
40 |
41 | ```ts
42 | import { Machine } from "xstate";
43 |
44 | interface Context {}
45 |
46 | type Event = { type: "EVENT_NAME" };
47 |
48 | type States = {};
49 |
50 | const machine = Machine({ ...config });
51 | ```
52 |
53 | Whereas `createMachine` asks you to insert it at the end:
54 |
55 | ```ts
56 | import { createMachine } from "xstate";
57 |
58 | interface Context {}
59 |
60 | type Event = { type: "EVENT_NAME" };
61 |
62 | type States = {};
63 |
64 | const machine = createMachine({ ...config });
65 | ```
66 |
67 | Whichever you choose, there is _no functional difference in the created machine_. The two functions reference the same code, and create the machine in the same way.
68 |
69 | ## What should I choose?
70 |
71 | Going forward, you should use `createMachine`. That’s the syntax that will be preferred when v5 releases. But if you're happy with Machine, you can keep using it.
72 |
--------------------------------------------------------------------------------
/content/posts/2021-04-29-should-this-be-a-state-or-in-context.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: "Should this be a state, or in context?"
3 | description: How to decide when to use state or context.
4 | tags:
5 | - context
6 | - state machine
7 | - xstate
8 | - state
9 | author: Matt Pocock
10 | excerpt: ""
11 | publishedAt: "2021-04-29"
12 | ogImage: "https://stately.ai/blog/2021-04-29-should-this-be-a-state-or-in-context.png"
13 | ---
14 |
15 | State machines offer several API’s for expressing state. Like other tools, you can keep arbitrary values in a store (usually expressed as an object) called `context`.
16 |
17 | This is handy for values which change over time and you need to keep updated, like the value of a form input:
18 |
19 | ```ts
20 | import { createMachine, assign } from "xstate";
21 |
22 | const machine = createMachine({
23 | context: {
24 | name: "",
25 | },
26 | on: {
27 | CHANGE_NAME: {
28 | actions: assign((context, event) => {
29 | return {
30 | name: event.value,
31 | };
32 | }),
33 | },
34 | },
35 | });
36 | ```
37 |
38 | Every time the `CHANGE_NAME` event is sent to the machine, we'll update the value in `context`. We can then use that value to display the value in our UI or send it to an API.
39 |
40 | XState also gives you another way of expressing state - through finite states. Let's imagine a modal:
41 |
42 | ```ts
43 | const machine = createMachine({
44 | initial: "closed",
45 | states: {
46 | closed: {
47 | on: {
48 | OPEN: "open",
49 | },
50 | },
51 | open: {
52 | on: {
53 | CLOSE: "close",
54 | },
55 | },
56 | },
57 | });
58 | ```
59 |
60 | Here, the modal's state is expressed through the `states: {}` attribute, which also defines which events can be received during each state. You can only `CLOSE` the modal when it's `open`, and vice versa.
61 |
62 | ## Which should I choose?
63 |
64 | The choice between using `context` and `states` isn't always clear. For instance, the modal machine above could be expressed using `context`:
65 |
66 | ```ts
67 | const machine = createMachine({
68 | context: {
69 | isOpen: false,
70 | },
71 | on: {
72 | OPEN: {
73 | actions: assign({ isOpen: true }),
74 | },
75 | CLOSE: {
76 | actions: assign({ isOpen: false }),
77 | },
78 | },
79 | });
80 | ```
81 |
82 | This gives you exactly the same functionality as the states-based one above - you can track when the modal is open and closed, and send the same events.
83 |
84 | The reason this can be expressed using both `states` and `context` is because _all of the events do the same thing no matter what state you’re in_. There are no events you need to declare as impossible in certain states.
85 |
86 | To show you what I mean, let’s imagine a form input inside a modal. We only want to allow changes to the form input while the modal is open.
87 |
88 | ```ts
89 | const machine = createMachine({
90 | initial: "closed",
91 | context: {
92 | name: "",
93 | },
94 | states: {
95 | closed: {
96 | on: {
97 | OPEN: "open",
98 | },
99 | },
100 | open: {
101 | on: {
102 | CLOSE: "close",
103 | CHANGE_NAME: {
104 | actions: assign((context, event) => {
105 | return {
106 | name: event.value,
107 | };
108 | }),
109 | },
110 | },
111 | },
112 | },
113 | });
114 | ```
115 |
116 | When the modal is in the `closed` state, the `CHANGE_NAME` event will not change the value in `context`. State machines are great at this - only allowing the things you want to happen to happen. Some other examples might be:
117 |
118 | - Not allowing users to submit a form while the previous API call is loading
119 | - Only allowing users to log in if they’re not already logged in
120 |
121 | ## Putting things in context
122 |
123 | You might be wondering - but, I _can_ express the above in `context`!
124 |
125 | ```ts
126 | const machine = createMachine({
127 | context: {
128 | name: "",
129 | isOpen: false,
130 | },
131 | on: {
132 | OPEN: { actions: assign({ isOpen: true }) },
133 | CLOSE: { actions: assign({ isOpen: false }) },
134 | CHANGE_NAME: {
135 | actions: assign((context, event) => {
136 | // This acts as the guard to prevent editing
137 | // the name while it's open
138 | if (!context.isOpen) return {};
139 | return {
140 | name: event.value,
141 | };
142 | }),
143 | },
144 | },
145 | });
146 | ```
147 |
148 | I think this is incorrect for two reasons. First, as requirements grow, so will the complexity of your logic. Let’s imagine that the modal can now be either `closing` (i.e. animating out) or `closed`. We’ll soon see an explosion of booleans, as I discussed in [this article on useState/useReducer](https://dev.to/mpocock1/usestate-vs-usereducer-vs-xstate-part-1-modals-569e).
149 |
150 | Second, XState is auto-documenting via the [XState visualiser](https://xstate.js.org/viz/). The more your logic is expressed in `states`, the easier it’s going to be to visualise. The machine above is basically a single state with its logic expressed in ways that XState can’t visualise.
151 |
152 | ## Rules to live by
153 |
154 | You should be keeping most of your state in context. That includes form values, API data - anything which cannot be expressed finitely.
155 |
156 | But state machines are powerful _because_ of their states. Use states when you want to express your logic visually, or gate events to certain states.
157 |
--------------------------------------------------------------------------------
/content/posts/2021-12-14-what-are-the-biggest-benefits-youve-had-from-using-state-machines.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: What are the biggest benefits you’ve had from using state machines?
3 | description: >-
4 | At Stately we’re fans of state machines, but we wanted to ask our
5 | community… what are the benefits that you’ve experienced from using state machines?
6 | tags:
7 | - weekly question
8 | - community
9 | - state machine
10 | author: Laura Kalbag
11 | excerpt: ""
12 | publishedAt: "2021-12-14"
13 | ogImage: "https://stately.ai/blog/2021-12-14-what-are-the-biggest-benefits-youve-had-from-using-state-machines.png"
14 | ---
15 |
16 | Last week we asked our community, “What are the biggest benefits you’ve had from using state machines?”
17 |
18 | At Stately, we’re obviously fans of state machines. Still, we wanted to ask our community the benefits they’ve experienced, whether they were working on a specific project or incorporating state machines into their everyday workflow.
19 |
20 | ## Reusability
21 |
22 | Nowadays, so much of tech is component-oriented, so it was fascinating to hear from Martin that he reused the same state machines across different frameworks.
23 |
24 |
25 |
26 | > I think that **the biggest benefit comes from being able to use the same state machine across different frameworks**. With XState, even if you just use React on your projects, you can share your state machine with your [insert framework name here] friends.
27 |
28 | ## Maintaining complex app logic
29 |
30 |
31 |
32 | Pat’s blog post goes into fascinating depth on his work with Crucible. The section on XState starts with Pat’s realization that he needed a state machine and ends with him moving much of their application logic into statecharts.
33 |
34 | > **We didn't start Crucible using XState but by the end of the project it was one of our most valuable tools…**
35 | >
36 | > …
37 | >
38 | > I was still new to statecharts and sort of overwhelmed by the whole idea so I needed to find a small feature I could prototype XState with where it would make sense and add recognizable value to a flow/process that could use more structure to it…
39 | >
40 | > …
41 | >
42 | > I built out the flow based on the services’ state and UI state, I defined all the valid transitions and where they’d go, I wired up the inputs/outputs to it, and then I turned it loose on matchmaking in an actual client and it worked beautifully.
43 | >
44 | > **I could look at the statechart and see the entire flow through the states**, I could see every valid transition that the statechart could take and where it would go, I could paste it into the XState visualizer and actually see a DIAGRAM OF ALL THE STATES AND WALK THROUGH THEM INTERACTIVELY.
45 |
46 | [Read all of Pat’s post on his blog](https://tivac.com/2020/10/19/crucible-rip/).
47 |
48 | ## Maintainability
49 |
50 | Maintainability is a popular feature of state machines, and Joshua is a fan.
51 |
52 |
53 |
54 | Matt’s article on ‘[useState vs useReducer vs XState - Part 1: Modals](/blog/usestate-vs-usereducer-vs-xstate-part-1-modals)’ shares examples of these different approaches and their maintainability. And he followed it up with his [React Finland talk, ‘Make legacy code delightful with statecharts’](https://www.youtube.com/watch?v=zll9uDQOOq0).
55 |
56 | ## Getting to the core of your logic
57 |
58 | The [discussion on our Discord](https://discord.com/channels/795785288994652170/795785288994652174/918546073268670534) focused on mindset and how state machines can help us better understand our app logic. Jan got the conversation started.
59 |
60 | > Certainly for me it must be that **it allows me to very quickly get to the essence and core behaviour of what I'm building**. Playing with boxes and arrows allow me to not get caught up in implementation details while figuring out how I want stuff to work.
61 | >
62 | > Afterwards, implementing actions and services just feels like filling in the blanks. Likewise hooking the machine up with my component is equally trivial: throw some `state.hasTag`, `state.context` and `send` in there, and you’ve got a stew going
63 |
64 | And Steve continued.
65 |
66 | > State machines make complex behaviors tractable; they help you think about the problem.
67 | >
68 | > State machines reveal complexities in ostensibly simple behaviors; they make you think about the problem.
69 | >
70 | > Yin and yang. Good cop, bad cop. **Thinking about your application behavior as a set of state machines focuses your mind on what's really going on inside that tangled mass of behaviors**.
71 |
72 | ## Robustness
73 |
74 | Horacio also explained how the robustness of apps built with state machines could give us more faith in our work.
75 |
76 | > Programming is all about confidence, and for me, **working with state machines gives me the same confidence on my code as writing tests**, with the addition to have a visual representation of my system that I can discuss, show and modify with all my teammates.
77 | >
78 | > Also having the confidence of refactoring code without the fear of breaking other parts of my app!!
79 | >
80 | > Definitely XState is one of my top additions of 2021 to my dev toolbelt! 💪
81 |
82 | That’s just what we like to hear!
83 |
84 | Thank you, everyone, for your responses. We love to hear about how you’re using state machines in your projects. If you’ve got any feedback you want to share with the Stately team, you can [find us on Twitter](https://twitter.com/statelyai) and join the community on [our Discord server](https://discord.gg).
85 |
86 | _Note: quotes have been minimally edited to add emphasis and clarity._
87 |
--------------------------------------------------------------------------------
/content/posts/2022-03-03-introducing-the-xstate-cli.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: "Introducing: The XState CLI"
3 | description: "Get ready to run XState’s typegen commands outside of VSCode in our all-new CLI."
4 | tags:
5 | - cli
6 | - xstate
7 | - announcement
8 | - typescript
9 | author:
10 | - Matt Pocock
11 | excerpt: "Get ready to run XState’s typegen commands outside of VSCode in our all-new CLI."
12 | publishedAt: "2022-03-03"
13 | ogImage: "https://stately.ai/blog/2022-03-03-introducing-the-xstate-cli.png"
14 | ---
15 |
16 | Around a month ago, we released [TypeScript Typegen](/blog/introducing-typescript-typegen-for-xstate) - an enormous upgrade to the TypeScript experience for XState.
17 |
18 | We’ve had a great response to it so far, but it’s only been available for VSCode users.
19 |
20 | Until now. With our new XState CLI, **you can get Typegen from the command line**.
21 |
22 | - Read the full documentation on the [`@xstate/cli` docs](https://xstate.js.org/docs/packages/xstate-cli).
23 | - Check out [our updated TypeScript Typegen guide](https://xstate.js.org/docs/guides/typescript.html#typegen).
24 | - Find the code on the [@xstate/cli GitHub repo](https://github.com/statelyai/xstate-tools/tree/main/apps/cli).
25 |
26 | ## Installation
27 |
28 | ```bash
29 | npm install @xstate/cli
30 | ```
31 |
32 | OR
33 |
34 | ```bash
35 | yarn add @xstate/cli
36 | ```
37 |
38 | ## Commands
39 |
40 | ### `xstate typegen `
41 |
42 | ```bash
43 | xstate typegen "src/**/*.tsx?"
44 | ```
45 |
46 | Run the typegen against a glob of files. This will scan every targeted file and generate a typegen file accompanying it. It will also import the typegen into your file, as described in [our typegen documentation](https://xstate.js.org/docs/guides/typescript.html#typegen).
47 |
48 | Ensure you wrap your glob in quotes so that it executes correctly. Otherwise, you’ll get unexpected results.
49 |
50 | #### Options
51 |
52 | ```bash
53 | xstate typegen "src/**/*.tsx?" --watch
54 | ```
55 |
56 | Runs the task on a watch, monitoring for changed files and running the typegen script against them.
57 |
58 | ## The Future
59 |
60 | We’re really excited about the CLI, and all the cool things it’ll enable. The typegen really is just the surface. If you’ve got ideas for what we could do with it, don’t hesitate to add a feature request to the [`xstate-tools` repo](https://github.com/statelyai/xstate-tools/issues).
61 |
--------------------------------------------------------------------------------
/content/posts/2022-03-11-xstate-vscode-extension-now-available-on-the-open-vsx-registry.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: XState VSCode extension now available on the Open VSX Registry
3 | description: >-
4 | If you use VSCodium, Coder, Gitpod or another editor with VSCode-compatible
5 | extensions, you can now install the XState VSCode extension from the Open VSX
6 | Registry.
7 | tags:
8 | - extension
9 | - open source
10 | - xstate
11 | - vscode
12 | author:
13 | - Laura Kalbag
14 | ogImage: 'https://stately.ai/blog/2022-03-15-xstate-vscode-extension-now-available-on-the-open-vsx-registry.png'
15 | excerpt: 'If you use VSCodium, Coder, Gitpod or another editor with VSCode-compatible
16 | extensions, you can now install the XState VSCode extension from the Open VSX
17 | Registry.'
18 | publishedAt: "2022-03-15"
19 | ---
20 |
21 | If you use VSCodium, Coder, Gitpod or another editor with VSCode-compatible extensions, you can now [install the XState VSCode extension from the Open VSX Registry](https://open-vsx.org/extension/statelyai/stately-vscode).
22 |
23 | We released our [XState VSCode extension](https://marketplace.visualstudio.com/items?itemName=statelyai.stately-vscode) a few weeks ago, which gives you visual editing, autocomplete, typegen and linting for XState. The same extension is now available for VSCodium, Coder and Gitpod, and any other editors with VSCode-compatible extensions through the Open VSX Registry.
24 |
25 | We had many requests to distribute the extension on the Open VSX Registry. As a person who uses [VSCodium](https://vscodium.com) myself, it was exciting to install the extension from inside VSCodium.
26 |
27 | 1. Open the command palette in VSCodium with `shift` + `cmd/ctrl` + `p`.
28 | 2. Search for the **Install Extensions** command and hit enter to open the Extensions search.
29 | 3. Search for **XState** to find the XState VSCode extension and install the extension using the **Install** button.
30 | 4. Once you have installed the extension, you can find the extension commands by searching for **XState** in the command palette.
31 |
32 | You can also [download the XState VSCode extension directly from the Open VSX Registry](https://open-vsx.org/extension/statelyai/stately-vscode).
33 |
34 | Please give us your feedback and let us know if you encounter any issues in [our Discord](https://discord.gg/xstate) or [our xstate-tools repository](https://github.com/statelyai/xstate-tools/issues).
--------------------------------------------------------------------------------
/content/posts/2022-03-15-introducing-the-new-stately-homepage.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: Introducing the new Stately homepage
3 | description: "Last week we launched the new Stately homepage, which we hope will make it easy to understand what Stately and XState are and help you convince your team to use state machines."
4 | tags:
5 | - stately
6 | - homepage
7 | - introduction
8 | author:
9 | - Laura Kalbag
10 | excerpt: ""
11 | publishedAt: "2022-03-16"
12 | ogImage: "https://stately.ai/blog/2022-03-16-introducing-the-new-stately-homepage.png"
13 | ---
14 |
15 | Last week we launched [the new Stately homepage](https://stately.ai), which we hope will make it easy to understand what Stately and XState are and help you convince your team to use state machines.
16 |
17 | You can watch us talk about the new design and its implementation during [last week’s office hours](https://youtu.be/WoPCd4D--Gk?t=771). I’m particularly impressed by David’s SVG arrows!
18 |
19 | And if you have any feedback about the homepage, please let us know on [our Discord](https://discord.gg/xstate). We always appreciate your thoughts.
20 |
--------------------------------------------------------------------------------
/content/posts/2022-03-23-stately-changelog-1.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: "Stately Changelog #1 - Snap To Elements"
3 | description: The Stately Editor changelog is where we discuss new features released to the Stately Editor beta.
4 | tags:
5 | - stately
6 | - announcement
7 | - editor
8 | - beta
9 | - changelog
10 | author:
11 | - Matt Pocock
12 | originalURL: ""
13 | excerpt: ""
14 | publishedAt: "2022-03-23"
15 | ogImage: "https://stately.ai/blog/2022-03-23-stately-changelog-1.png"
16 | ---
17 |
18 | Happy Wednesday! Time for our first Editor Changelog blog, where we’ll talk about the new updates we’ve shipped in the editor.
19 |
20 | ## Snap To Elements
21 |
22 | When you’re placing states and events in the canvas, you’ll now be able to snap them to surrounding elements.
23 |
24 | Snapping is a hugely requested feature and should help make your charts neater and more legible.
25 |
26 |
27 |
28 | So far, we’ve implemented snapping to the _center_ of elements only. We’re keen to [hear your feedback](https://github.com/statelyai/editor-feedback/issues) if you want more snapping!
29 |
30 | ## Right-click menu
31 |
32 | You can now right-click events and states to perform actions including:
33 |
34 | - Renaming states/events
35 | - Making states the 'initial' state
36 | - Adding guards
37 | - Turning events into self-transitions
38 |
39 | And many more.
40 |
41 |
42 |
43 | ## Visual update for events
44 |
45 | We’ve streamlined the way our events look to make them more visually distinct from states. This new look keeps the focus on the arrow, the direction of travel, and the flow of the chart.
46 |
47 | 
48 |
49 | ## Improvements to VSCode output
50 |
51 | We’ve massively improved the way we handle transition targets in VSCode. Instead of every transition having an ugly `#(machine).state1.state2`, the VSCode extension will now make the most idiomatic choice out of `targetState`, `.targetState`, or `targetState.child`.
52 |
53 | ```ts
54 | const machine = createMachine({
55 | initial: "a",
56 | states: {
57 | a: {
58 | on: {
59 | EVENT: {
60 | // Before
61 | target: "#(machine).b",
62 | },
63 | },
64 | },
65 | b: {},
66 | },
67 | });
68 |
69 | const machine = createMachine({
70 | initial: "a",
71 | states: {
72 | a: {
73 | on: {
74 | EVENT: {
75 | // After
76 | target: "b",
77 | },
78 | },
79 | },
80 | b: {},
81 | },
82 | });
83 | ```
84 |
85 | As part of this work, we’ve also improved how we handle `internal` - you’ll now get proper warnings inside the visual editor when you use `internal` incorrectly.
86 |
87 | ## Other Improvements
88 |
89 | We’ve been hard at work fixing bugs in the VSCode extension and the CLI. You can keep up to date with those changes in our [`xstate-tools`](https://github.com/statelyai/xstate-tools/releases) repo.
90 |
--------------------------------------------------------------------------------
/content/posts/2022-03-28-stately-is-hiring.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: "Stately is hiring!"
3 | description: We’re hiring for a frontend engineer, backend engineer, developer advocate and product designer at Stately.
4 | tags:
5 | - stately
6 | - hiring
7 | author:
8 | - Laura Kalbag
9 | excerpt: ""
10 | publishedAt: "2022-03-28"
11 | ogImage: "https://stately.ai/2022-03-28-stately-is-hiring.png"
12 | ---
13 |
14 | We’re hiring for a frontend engineer, backend engineer, developer advocate and product designer at Stately. You can [check out the Careers at Stately page on Notion](https://statelyai.notion.site/Careers-at-Stately-db3d704abd8f41058e5361e5ab9c1098).
15 |
16 | ## About Stately
17 |
18 | Stately is building **the visual future of software development.**
19 |
20 | At Stately, we want to make app and business logic accessible to the entire team and eliminate barriers between development, design, and product to make it easier to build and maintain complex applications quickly and robustly.
21 |
22 | We enable development teams to collaborate effectively on even the most complex logic and flows with visual tools and insightful services. Helping them speak a common language so that the specifications, designs, and code are always synchronized, up-to-date, and visually clear.
23 |
24 | We’re building a team inspired to work on this mission to make software development better for everyone and practice what we preach, both inside Stately and everywhere else.
25 |
26 | ## Questions from our office hours stream last week
27 |
28 | During [our office hours live stream last week](https://www.youtube.com/watch?v=zYCnVkaUT3w), we answered questions about working with Stately. You can find the questions and links to the timecode with our responses below.
29 |
30 | ### About the job listings
31 |
32 | - [What are the responsibilities of the product designer role?](https://www.youtube.com/watch?v=zYCnVkaUT3w&t=826s)
33 | - [What is the hiring process?](https://www.youtube.com/watch?v=zYCnVkaUT3w&t=943s)
34 | - [What is the definition of a senior developer? (And other roles)](https://www.youtube.com/watch?v=zYCnVkaUT3w&t=1627s)
35 | - [Is there a trial period?](https://www.youtube.com/watch?v=zYCnVkaUT3w&t=1175s)
36 |
37 | ### About Stately
38 |
39 | - [When was the company founded, and how are you financially sustainable?](https://www.youtube.com/watch?v=zYCnVkaUT3w&t=1115s)
40 | - [What exciting projects would you be working on at Stately?](https://www.youtube.com/watch?v=zYCnVkaUT3w&t=705s)
41 |
42 | ### About the Stately team
43 |
44 | - [How many people are on the Stately team?](https://www.youtube.com/watch?v=zYCnVkaUT3w&t=1225s)
45 | - [Should I apply if I feel underqualified? What would help me get the role in the future?](https://www.youtube.com/watch?v=zYCnVkaUT3w&t=1313s)
46 | - [How well can Stately support neurodivergent people?](https://www.youtube.com/watch?v=zYCnVkaUT3w&t=1969s)
47 |
48 | ### About timezones and locations
49 |
50 | - [Are these jobs remote? Yes!](https://www.youtube.com/watch?v=zYCnVkaUT3w&t=806s)
51 | - [Which timezones do Stately currently work within?](https://www.youtube.com/watch?v=zYCnVkaUT3w&t=1753s)
52 | - [Where are you folks based?](https://www.youtube.com/watch?v=zYCnVkaUT3w&t=1802s)
53 |
54 | ### About the day-to-day at Stately
55 |
56 | - [What does team collaboration look like at Stately?](https://www.youtube.com/watch?v=zYCnVkaUT3w&t=1364s)
57 | - [What is the work culture like from an insider perspective?](https://www.youtube.com/watch?v=zYCnVkaUT3w&t=1845s)
58 | - [Are there a lot of video calls at Stately?](https://www.youtube.com/watch?v=zYCnVkaUT3w&t=1441s)
59 | - [What is the balance of sync vs. async collaboration at Stately?](https://www.youtube.com/watch?v=zYCnVkaUT3w&t=1508s)
60 | - [What is a good day at Stately vs. a bad day at Stately?](https://www.youtube.com/watch?v=zYCnVkaUT3w&t=2029s)
--------------------------------------------------------------------------------
/content/posts/2022-03-29-introducing-the-new-stately-roadmap.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: Introducing the new Stately Roadmap
3 | description: "We’ve added a Roadmap to our Documentation, so you know what we’re currently working on and what features are coming up soon."
4 | tags:
5 | - stately
6 | - roadmap
7 | - introduction
8 | author:
9 | - Laura Kalbag
10 | publishedAt: "2022-03-29"
11 | ogImage: "https://stately.ai/blog/2022-03-29-introducing-the-new-stately-roadmap.png"
12 | ---
13 |
14 | This week we’ve added [our Roadmap](https://xstate.js.org/docs/roadmap) to the XState documentation.
15 |
16 | Many of you have requested a roadmap to help you determine if it’s the right time to integrate XState and Stately tools into your team’s workflow. We’ve added a simple Roadmap so you know what we’re currently working on and what features are coming up soon.
17 |
18 | ## Upcoming features
19 |
20 | To give you an idea of what we’re working on, below are the features currently planned for April - June 2022.
21 |
22 | ### XState
23 |
24 | - XState v5 Alpha
25 |
26 | ### Editor
27 |
28 | - Billing and Teams
29 | - Feature parity with XState
30 | - Authentication bug fixes
31 | - Welcome emails
32 | - Inline editing
33 | - Simulation mode
34 | - Markdown descriptions
35 | - Workflow creation
36 |
37 | ### Documentation
38 |
39 | - Stately tools visibility
40 | - Update and rework
41 |
42 | ## Please give us your feedback and suggestions
43 |
44 | We prioritize features based on your feedback. Please let us know if you have feedback or suggestions in [our GitHub Discussions](https://github.com/statelyai/xstate/discussions), [our Discord](https://discord.gg/xstate) or on [Twitter](https://twitter.com/statelyai).
45 |
46 |
--------------------------------------------------------------------------------
/content/posts/2022-04-05-building-a-video-player.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: Building a video player with XState and Stately tools
3 | description: "A few weeks ago we uploaded a new video to the Stately YouTube channel showing how you can build basic video player functionality using XState and Stately tools."
4 | tags:
5 | - xstate
6 | - modeling
7 | - tutorial
8 | author:
9 | - Laura Kalbag
10 | publishedAt: "2022-04-05"
11 | ogImage: "https://stately.ai/2022-04-05-building-a-video-player.png"
12 | ---
13 |
14 | A few weeks ago we uploaded a new video to the [Stately YouTube channel](http://youtube.com/c/statelyai) showing how you can build basic video player functionality using XState and Stately tools. You can watch the video below or [use the chapter links](/#video-chapters) to jump to the chapter you want to watch.
15 |
16 |
17 |
18 | ## Video chapters
19 |
20 | - [0:00](https://www.youtube.com/watch?v=3wZBSeLxVEw&t=0s) What we want to build
21 | - [2:52](https://www.youtube.com/watch?v=3wZBSeLxVEw&t=172s) Modeling the video player
22 | - [9:43](https://www.youtube.com/watch?v=3wZBSeLxVEw&t=583s) Implementing the state machine
23 | - [19:49](https://www.youtube.com/watch?v=3wZBSeLxVEw&t=1189s) Modeling with the visual editor
24 | - [22:10](https://www.youtube.com/watch?v=3wZBSeLxVEw&t=1330s) Editing the state machine
25 | - [25:05](https://www.youtube.com/watch?v=3wZBSeLxVEw&t=1505s) Editing the state machine in the visual editor
26 |
27 | ## We want your suggestions and feedback
28 |
29 | Please let us know what we should demo for you! Share your feedback or suggestions in [our GitHub Discussions](https://github.com/statelyai/xstate/discussions), [our Discord](https://discord.gg/xstate) or [Twitter](https://twitter.com/statelyai).
--------------------------------------------------------------------------------
/content/posts/2022-05-03-whats-new-may-2022.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: "What’s new in May 2022?"
3 | description: Updates to XState, @xstate/react and @xstate/fsm in the last month.
4 | tags:
5 | - stately
6 | - xstate
7 | - announcement
8 | - release
9 | author:
10 | - Laura Kalbag
11 | publishedAt: "2022-05-03"
12 | ogImage: "https://stately.ai/blog/2022-05-03-whats-new-may-2022.png"
13 | ---
14 |
15 | What’s new to XState and Stately for May 2022?
16 |
17 | ## Updates in XState
18 |
19 | With a few updates to @xstate/react and @xstate/fsm last month, our headline release was the `waitFor()` helper function.
20 |
21 | Read all the release notes and patch notes in the [XState GitHub repository releases](https://github.com/statelyai/xstate/releases).
22 |
23 | ### `waitFor()`
24 |
25 | The new `waitFor(...)` helper function asynchronously waits for an actor’s emitted value to satisfy a predicate before a timeout.
26 |
27 | Example usage:
28 |
29 | ```ts
30 | import { waitFor } from 'xstate/lib/waitFor';
31 |
32 | // ...
33 | const loginService = interpret(loginMachine).start();
34 |
35 | const loggedInState = await waitFor(loginService, state =>
36 | state.hasTag('loggedIn')
37 | );
38 |
39 | loggedInState.hasTag('loggedIn'); // true
40 | ```
41 |
42 | ### Updates in the @xstate/react package
43 |
44 | The @xstate/react package contains utilities for using XState with React. Find out more in the [@xstate/react package readme](https://github.com/statelyai/xstate/tree/main/packages/xstate-react).
45 |
46 | #### React 18
47 |
48 | The @xstate/react package now accepts React 18 as a peer dependency, and we rewrote the implementation to use the `use-sync-external-store` package. The package uses a shim to keep compatibility with older versions of React, so there is no need to worry if you haven’t upgraded yet.
49 |
50 | #### Subscribing to stopped interpreters
51 |
52 | Subscribing to a stopped interpreter will now always immediately emit the interpreter’s state and call a completion callback.
53 |
54 | ### `asEffect` and `asLayoutEffect` removed
55 |
56 | We have removed the `asEffect` and `asLayoutEffect` action creators. These action creators didn’t fit the React model well and had the potential to cause issues as their existence suggested that they might be easy to use.
57 |
58 | If you want to execute actions at those exact times, you can either make a call directly from those effects or send events to the machine from those effects and execute explicit actions in response to said events.
59 |
60 | ### `useMachine` and `useService` with @xstate/fsm
61 |
62 | We changed the signatures of `useMachine` and `useService` integrating with @xstate/fsm to match their signatures with their related hooks integrating with XState. Both now only accept a single generic. `useMachine` accepts `TMachine`, and `useService` accepts `TService`.
63 |
64 | ### Updates in the @xstate/fsm package
65 |
66 | @xstate/fsm is a minimal, 1kb implementation of XState for finite state machines. Find out more in the [@xstate/fsm package readme](https://github.com/statelyai/xstate/tree/main/packages/xstate-fsm).
67 |
68 | #### `.start()`
69 |
70 | When you call .start() without any argument, it now always starts from the machine’s initial state, matching the behavior of XState itself.
71 |
72 | ## More coming soon!
73 |
74 | If you want to know more about what we’ve got planned, you can [check out our Roadmap](https://xstate.js.org/docs/roadmap/). Got any feedback, or want to suggest features? [Share your thoughts in the XState discussions](https://github.com/statelyai/xstate/discussions).
75 |
76 | We’re also looking for your feedback on specific ideas in our [Stately RFCs (Requests for comment)](https://github.com/statelyai/rfcs).
--------------------------------------------------------------------------------
/content/posts/2022-06-07-whats-new-june-2022.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: "What’s new in June 2022?"
3 | description: Updates to XState, @xstate/test and the Stately editor in the last month.
4 | tags:
5 | - stately
6 | - xstate
7 | - announcement
8 | - release
9 | - lightmode
10 | - xstate test
11 | author:
12 | - Laura Kalbag
13 | publishedAt: "2022-06-07"
14 | ogImage: "https://stately.ai/blog/2022-06-07-whats-new-june-2022.png"
15 | ---
16 |
17 | We’ve had a busy month and have plenty to share with you this June!
18 |
19 | ## Another Stately update
20 |
21 | In May, we welcomed three new people to the Stately team. Kevin Maes and Anders Mellson join us as engineers, and Nick Perich as our product designer. Watch all three of them introduce themselves in [our office hours live stream from May 20](https://youtu.be/4WwaSZ-ciRI?t=127).
22 |
23 | ## XState Test v1 alpha
24 |
25 | Last week we released an alpha version of the XState Test package.
26 |
27 |
28 |
29 | - Read more in the [model-based testing section in our alpha docs](https://graph-docs.vercel.app/model-based-testing/intro).
30 | - Find the [XState test tag release notes on GitHub](https://github.com/statelyai/xstate/releases/tag/%40xstate%2Ftest%401.0.0-alpha.0).
31 | - [Watch the video above on Twitter](https://twitter.com/statelyai/status/1531250605313892352).
32 |
33 | ## Light mode in the Stately visual editor
34 |
35 | Nick and Anders got straight to work in their first week at Stately, creating light mode for the visual editor. We will keep improving both light mode and dark mode in the future, but we thought the initial designs were too good not to share with everyone!
36 |
37 | 
38 |
39 | Toggle “Switch to light mode” in the editor’s menu to view the editor in light mode. Toggle “Switch to dark mode” to switch back to dark mode.
40 |
41 | 
42 |
43 | ## And there’s more to come!
44 |
45 | Want to know more about what we’ve got planned? [Check out our Roadmap](https://xstate.js.org/docs/roadmap/). Got any feedback or want to suggest features? [Share your thoughts in the XState discussions](https://github.com/statelyai/xstate/discussions).
46 |
47 | We’re also looking for your feedback on XState snippets, errors in XState, and more in our [Stately RFCs (Requests for comments)](https://github.com/statelyai/rfcs).
--------------------------------------------------------------------------------
/content/posts/2022-06-13-nesting-typegen-files.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: "Nesting XState typegen files"
3 | description: What is file nesting in VS Code and how to enable it for XState's generated type files.
4 | tags:
5 | - stately
6 | - extension
7 | - open source
8 | - xstate
9 | - vscode
10 | author:
11 | - Anders Bech Mellson
12 | publishedAt: "2022-06-13"
13 | ogImage: "https://stately.ai/blog/2022-06-13-nesting-typegen-files.png"
14 | ---
15 |
16 | Our latest update to the [XState VS Code extension](https://marketplace.visualstudio.com/items?itemName=statelyai.stately-vscode) has made it easy to enable file nesting for typegen files. But what is file nesting?
17 |
18 | ## Explorer file nesting
19 |
20 | [VS Code introduced file nesting](https://code.visualstudio.com/updates/v1_67#_explorer-file-nesting) in version 1.67 back in April of 2022. This feature is elegant as it allows you to group related files in the explorer view of VS Code.
21 |
22 | Our friend Erik Rasmussen quickly found this feature works well with the generated type files for XState. Thanks to Erik for his great idea!
23 |
24 |
25 |
26 | ## Show me
27 |
28 | The image below shows the explorer in VS Code without file nesting enabled; you have a machine source file alongside a generated type file for that machine.
29 |
30 | 
31 |
32 | After enabling file nesting for typegen files, VS Code explorer allows you to nest and collapse the generated file under the source file.
33 |
34 | 
35 |
36 | ### Enable nesting
37 |
38 | If you’re using our VS Code extension and haven’t manually enabled file nesting for typegen files, you will see a helper prompt allowing you to enable file nesting with a click.
39 | The prompt will show when you open a file with a machine.
40 | If you miss the prompt, you can enable or disable file nesting as described in the next section.
41 |
42 | ### Disable nesting
43 |
44 | You can disable, or enable, the file nesting by using the `Xstate: Nest Typegen Files` toggle in your VS Code settings.
45 | 
46 |
47 | PS: If you’re unsure what typegen is in XState, [read this post where we introduced TypeScript typegen for XState](https://stately.ai/blog/introducing-typescript-typegen-for-xstate).
48 |
--------------------------------------------------------------------------------
/content/posts/2022-06-20-what-is-xstate-used-for.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: What is XState used for?
3 | description: XState can be used wherever JavaScript runs, whether on the backend or frontend. Because the code it creates can be visualized, it’s great at handling complex use cases.
4 | tags:
5 | - xstate
6 | - react
7 | - node
8 | - vue
9 | - redux
10 | author:
11 | - Matt Pocock
12 | originalURL: ""
13 | ogImage: "https://stately.ai/blog/2022-06-21-what-is-xstate-used-for.png"
14 | excerpt: "XState can be used wherever JavaScript runs, whether on the backend or frontend. Because the code it creates can be visualized, it’s great at handling complex use cases."
15 | publishedAt: "2022-06-21"
16 | ---
17 |
18 | XState can be used wherever JavaScript runs, whether on the backend or frontend. Because the code it creates can be visualized, it’s great at handling complex use cases - being able to see what a complex piece of code does can be extremely useful.
19 |
20 | Let’s look at each use case one-by-one.
21 |
22 | ## On the web
23 |
24 | XState can be used in any frontend application to manage state. It has first-class integrations for [React](https://reactjs.org/), [Vue](https://vuejs.org/), [Svelte](https://svelte.dev/), as well as an upcoming [Solid](https://www.solidjs.com/) integration. It also works well in [Angular](https://angularjs.org/) without any integrations needed.
25 |
26 | You can try it in a Vanilla JS app by running this simple piece of code:
27 |
28 | ```ts
29 | import { createMachine, interpret } from "xstate";
30 |
31 | const machine = createMachine({
32 | initial: "waiting",
33 | states: {
34 | waiting: {
35 | after: {
36 | 2000: "alerted",
37 | },
38 | },
39 | alerted: {
40 | entry: () => {
41 | alert("Hello from the state machine!");
42 | },
43 | },
44 | },
45 | });
46 |
47 | interpret(machine).start();
48 | ```
49 |
50 | In this example, the machine will wait for 2 seconds, then call `alert()` to let you know it’s alive.
51 |
52 | There are plenty of ways XState can be used on the frontend - let’s talk about two of the most common patterns:
53 |
54 | ### Complex components
55 |
56 | Most frontend apps split their code into components - individual pieces which can be reused across the app. If need to build a complex component, you can use XState to co-ordinate it.
57 |
58 | A great example of this is the library [Zag.js](https://zagjs.com/components/react/accordion), which is using XState-style syntax and statecharts to build reusable components across frameworks. You can even [see them visualized](https://state-machine-viz.vercel.app/accordion) using Stately’s tools.
59 |
60 | ### Global state
61 |
62 | You can also use XState to manage global state in your apps. A common pattern is the [Flux](https://facebook.github.io/flux/docs/in-depth-overview/) architecture, where you dispatch events to a single top-level store. Parts of your app can subscribe to updates from that store, using [selectors](https://redux.js.org/usage/deriving-data-selectors).
63 |
64 | XState can **replace global state managers like [Redux](https://redux.js.org/) or [Vuex](https://vuex.vuejs.org/)**, with one major benefit - your global state can be visualised and [visually edited](https://stately.ai/editor). XState gives you the ability to create a global store, dispatch events to it, and subscribe to only the pieces that matter. See our specific instructions in [React](https://xstate.js.org/docs/recipes/react.html#global-state-react-context) for more info.
65 |
66 | ## Native/extensions
67 |
68 | XState is also extremely useful in [React Native](https://reactnative.dev/) or [Electron](https://www.electronjs.org/) apps, Browser extensions and IDE extensions. Since XState doesn’t use any browser API’s, you can use it anywhere JavaScript runs.
69 |
70 | For instance, we use XState at Stately to [co-ordinate our VSCode extension](https://github.com/statelyai/xstate-tools/blob/6a91d6a5cdd4cf73c882175a2ad5fbe3b2a9910d/apps/extension/client/src/editorWebviewScript.ts#L90). [Centered](https://www.centered.app/) uses XState extensively in their Electron and React Native apps to co-ordinate timers, control app updates and handle complex user interactions.
71 |
72 | ## Backend
73 |
74 | You can use XState in [Node.js](https://nodejs.org/en/) or [Deno](https://deno.land/) to build [serverless functions](https://vercel.com/docs/concepts/functions/serverless-functions) or persistent servers.
75 |
76 | For lambda functions, XState exposes a function called [`waitFor`](https://xstate.js.org/docs/guides/interpretation.html#waitfor), which allows you to wait for a state machine to be in a certain state. This allows you to use XState inside `async` functions with ease.
77 |
78 | To learn more about XState in the backend, see our [recent video](https://www.youtube.com/watch?v=qqyQGEjWSAw) introducing the topic.
79 |
80 | ## Scripting and CLIs
81 |
82 | XState can be used when running scripts or CLIs to co-ordinate long-running processes.
83 |
84 | The most famous example of this in the wild is the frontend framework [Gatsby](https://www.gatsbyjs.com/). They use XState in their build process and development server to co-ordinate file-system changes and parallelize multiple processes. This means their entire build system is visualisable - an incredibly boon for such a complex process.
85 |
86 | ## Summary
87 |
88 | XState works anywhere JS runs - and folks are using it in the wild for _all sorts_ of use cases. Any time you’re building something that feels remotely complex, you can use XState to simplify your code and enable powerful visual tooling.
89 |
--------------------------------------------------------------------------------
/content/posts/2022-07-06-whats-new-july-2022.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: "What’s new in July 2022?"
3 | description: Search for machines, pinch to zoom, nest typegen files and more! Find out the latest features in the Stately editor and XState VS Code extension.
4 | tags:
5 | - stately
6 | - xstate
7 | - announcement
8 | - editor
9 | - search
10 | - typegen
11 | - survey
12 | - roadmap
13 | author:
14 | - Laura Kalbag
15 | publishedAt: "2022-07-06"
16 | ogImage: "https://stately.ai/blog/2022-08-03-whats-new-august-2022.png"
17 | ---
18 |
19 | On top of our usual minor improvements and bug fixes, we’ve got great new features to share with you in July!
20 |
21 | ## Search for machines
22 |
23 | Thanks to Anders’ hard work, the [Discover page](https://stately.ai/registry/discover) now has a fully-featured search where you can find and filter through all the machines our community has made.
24 |
25 | The filters can limit your search by source, features and number of states.
26 |
27 | 
29 |
30 | We have more planned for search in the future that we can’t wait to share with you.
31 |
32 | ## Pinch to zoom
33 |
34 | Trackpad fans rejoice; you can now pinch to zoom in and out to navigate the editor’s canvas by touch. This feature was a popular request at a workshop Matt gave, so he implemented it the following day! If you prefer a keyboard or mouse, you can also use the zoom in and out buttons or the **+** and **-** keyboard shortcuts.
35 |
36 | ## Nesting typegen files
37 |
38 | You’re missing out if you’re not using [our XState VS Code extension](https://marketplace.visualstudio.com/items?itemName=statelyai.stately-vscode) yet! After a top tip from our friend Erik Rasmussen, Anders added the feature to our VS Code extension. Read [Anders’ blog post on nesting XState typegen files](/blog/nesting-xstate-typegen-files) for more details.
39 |
40 | ## Labels on quick action buttons
41 |
42 | The quick action buttons for adding states and guarded transitions are now labeled with **+ State** and **+ Guard** to make the buttons’ function clearer. Improvements that make the editor’s interface easier to understand and use are a priority for us, and we appreciate any feedback you have for improvements that would benefit you.
43 |
44 | 
45 |
46 | ## More upcoming features
47 |
48 | We’ve got many more features coming up. Watch [our office hours from last week](https://www.youtube.com/watch?v=4v_M3HcZc3U) and [office hours from June 24](https://www.youtube.com/watch?v=qmbeYvcA3Ks) for demos of [smoother transition lines](https://www.youtube.com/watch?v=qmbeYvcA3Ks&t=530s), [fit to content on initial render](https://www.youtube.com/watch?v=4v_M3HcZc3U&t=1214s) and [parity between XState and the Stately editor](https://www.youtube.com/watch?v=4v_M3HcZc3U&t=208s).
49 |
50 | ## Suggest features and help us prioritize our roadmap
51 |
52 | We’ve also started using Canny to collect your feedback and help us prioritize planned features in the last month. If there’s anything you want from XState or our Stately tools, please create a post or [upvote and give feedback on proposed features](https://statelyai.canny.io).
53 |
54 | Visit [our Canny roadmap](https://statelyai.canny.io) to make feature requests, submit feedback, view the roadmap and vote on features.
55 |
56 | 
57 |
58 | ## New videos on our YouTube channel
59 |
60 | Matt has made five great videos for [our YouTube channel](https://www.youtube.com/statelyai) to help you learn about using XState. Join our 1000+ subscribers and find out more about:
61 |
62 | - [How XState scales to ANY requirement](https://www.youtube.com/watch?v=AQHpXDo_S1k)
63 | - [XState in the backend](https://www.youtube.com/watch?v=qqyQGEjWSAw)
64 | - [Complex forms in XState & React](https://www.youtube.com/watch?v=Xa0H-vf2VuQ)
65 | - [Is XState good with TypeScript?](https://www.youtube.com/watch?v=EIi6CV4Bc_Q)
66 | - [How to decide between useState, useReducer and XState](https://www.youtube.com/watch?v=FrNXCJa5FLs)
67 |
68 | ## Please give us feedback in our yearly survey
69 |
70 | And finally, [the Stately 2022 survey](https://stately.ai/survey) is out, and we would love you to add your response to help us make our tools work for you. All the questions are optional, and it will take just five minutes of your time.
--------------------------------------------------------------------------------
/content/posts/2022-08-03-whats-new-august-2022.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: "What’s new in August 2022?"
3 | description: Get up and running faster with our XState VS Code extension and enjoy all the design details in the Stately studio experience.
4 | tags:
5 | - stately
6 | - xstate
7 | - announcement
8 | - vscode extension
9 | - studio
10 | - survey
11 | author:
12 | - Laura Kalbag
13 | publishedAt: "2022-08-05"
14 | ogImage: "https://stately.ai/blog/2022-08-03-whats-new-august-2022.png"
15 | ---
16 |
17 | ## Updates to our VS Code extension
18 |
19 | Our [XState VS Code extension](https://marketplace.visualstudio.com/items?itemName=statelyai.stately-vscode) has now been installed 10k times! Install the extension yourself from inside VS Code or find the [XState extension on the Open VSX Registry](https://stately.ai/blog/xstate-vscode-extension-now-available-on-the-open-vsx-registry) to enjoy the following new features.
20 |
21 | ### `xsm` snippet
22 |
23 | We want to make it fast and easy to use XState and the visual editor in your code. By adding the `xsm` snippet to our VS Code extension, we’ve made it possible to go from nothing to a full-blown machine you can open in the visual editor in a few keystrokes.
24 |
25 | Use our new `xsm` snippet ([Anders says “think **X** **S**tate **M**achine”](https://youtu.be/EkhWpJfVLDo?t=155)) with the latest version of the extension to insert a state machine template into your code, with the cursor ready for you to type the name of the machine.
26 |
27 | ```js
28 | import { createMachine } from 'xstate';
29 | const nameOfMachine = createMachine({
30 | id: 'nameOf',
31 | initial: 'initialState',
32 | states: {
33 | initialState: {},
34 | }
35 | });
36 | ```
37 |
38 | Just give your machine a name, hit “Open visual editor,” and you’ll be able to continue creating your machine with the visual editor.
39 |
40 | 
41 |
42 | ### The editor now syncs with your VS Code theme
43 |
44 | You can now set your light mode or dark mode preference for the visual editor inside the VS Code extension:
45 |
46 | - Auto: syncs to your VS Code preference
47 | - Light: always uses light mode
48 | - Dark: always uses dark mode
49 |
50 | 
51 |
52 | 
53 |
54 | If the editor is open when you change the setting, you’ll need to close and re-open the editor tab to view the change.
55 |
56 | ### Initial support for non-VS Code editors
57 |
58 | If you don’t use VS Code, we haven’t forgotten about you! We intend to support more code editors in the future and have recently taken the first step of making it easier to edit machine code using other code editors. Watch [Anders’ demo using Webstorm](https://www.youtube.com/watch?v=EkhWpJfVLDo&t=252s) during last week’s office hours to find out more.
59 |
60 | ## Updates to Stately editor
61 |
62 | If you haven’t used the [Stately editor](https://stately.ai/editor) in a while, you’re in for a treat!
63 |
64 | ### Canvas refinements
65 |
66 | We’ve made some small changes that have significantly changed how machines look and behave. Icons are now only used to distinguish the history states and final states, reducing the noise and increasing the readability of your machines.
67 |
68 | 
69 |
70 | The transition line drawing algorithm has been improved further for straighter, more reasonable lines with fewer bends. The lines are now highlighted on hover, making them easier to select. We’ll continue to improve the algorithm so that it’s more intelligent about drawing even better lines.
71 |
72 | We’ve also removed the terminal squares at the end of the transition lines and put a little space between the transition lines and nodes. These subtle changes make the machines look less crowded, helping you focus more on your modeling.
73 |
74 | ### Select all with the keyboard shortcut
75 |
76 | You can now use the cmd/ctrl **+** a keyboard shortcut to select all nodes and transitions in the editor. This shortcut is so common that you’ve probably tried to use it already… now the shortcut will work!
77 |
78 | 
79 |
80 | ## New privacy options
81 |
82 | We now have a modal asking for your consent the next time you log into the Stately Studio. We are sending some non-personal activity data to Mixpanel to help us understand how you use our features, but we need your permission to connect this data to a hash of your user ID. Many tech companies won’t ask for your explicit consent for similar activities. Still, at Stately, we want to use best practices regarding your privacy and be transparent about the minimal data we collect, how we use that data, and how we design for privacy by default. You can update your choices at any time in the studio settings.
83 |
84 | ## Please give us feedback in our yearly survey
85 |
86 | Soon we’ll be closing [the Stately 2022 survey](https://stately.ai/survey). Do you know someone who isn’t using our tools but should be? Please get them to respond to our survey! We’d love to understand what features folks need to start using Stately tools. And if you’ve not responded yet, get your response in soon! All the questions are optional, and it will take just five minutes of your time.
--------------------------------------------------------------------------------
/content/posts/2022-08-10-get-started-with-xstate-using-xsm-snippet.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: "XState + VS Code: xsm snippet"
3 | description: Create a state machine in seconds and edit using our visual editor.
4 | tags:
5 | - stately
6 | - xstate
7 | - vscode extension
8 | - snippet
9 | author:
10 | - Laura Kalbag
11 | publishedAt: "2022-08-10"
12 | ogImage: "https://stately.ai/blog/2022-08-10-get-started-with-xstate-using-xsm-snippet.png"
13 | ---
14 |
15 | Using the XState extension for VS Code, you can create a state machine in seconds and edit the machine using our visual editor. Use the `xsm` snippet to quickly generate the code required for your state machine, then drag and drop inside our visual editor to rapidly model your machine.
16 |
17 |
--------------------------------------------------------------------------------
/content/posts/2022-08-17-goodbye-use-effect-at-react-next.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: "“Goodbye, useEffect” at React Next conference"
3 | description: Create a state machine in seconds and edit using our visual editor.
4 | tags:
5 | - stately
6 | - xstate
7 | - studio
8 | - conference
9 | - talk
10 | author:
11 | - David Khourshid
12 | publishedAt: "2022-08-17"
13 | ogImage: "https://stately.ai/blog/2022-08-17-goodbye-use-effect-at-react-next.png"
14 | ---
15 |
16 | From fetching data to fighting with imperative APIs, side effects are one of the biggest sources of frustration in web app development. And let’s be honest, putting everything in useEffect hooks doesn’t help much.
17 |
18 | Thankfully, there is a science (well, math) to side effects, formalized in state machines and statecharts, that can help us visually model and understand how to declaratively orchestrate effects, no matter how complex they get. In this talk, David ditches the `useEffect` hook and discovers how these computer science principles can be used to simplify effects in our React apps.
19 |
20 |
--------------------------------------------------------------------------------
/content/posts/2022-08-23-building-a-resizable-panel.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: "Building a resizable panel"
3 | description: Farzad and David use XState to build the logic for a resizable panel with React in an impromptu live stream.
4 | tags:
5 | - stately
6 | - xstate
7 | - studio
8 | - react
9 | author:
10 | - Farzad Yousefzadeh
11 | publishedAt: "2022-08-22"
12 | ogImage: "https://stately.ai/blog/2022-08-22-building-a-resizable-panel.png"
13 | ---
14 |
15 | Farzad and David use XState to build the logic for a resizable panel with React in an impromptu live stream.
16 |
17 | [Check out the accompanying code on CodeSandbox](https://codesandbox.io/s/resizable-panel-example-jjgkzl?file=/src/index.tsx).
18 |
19 | [Watch part 2](/blog/building-a-resizable-panel-part-2).
20 |
21 |
--------------------------------------------------------------------------------
/content/posts/2022-08-31-building-a-resizable-panel.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: "Building a resizable panel: Part 2"
3 | description: Farzad and David add more features to their resizable panel using XState and React.
4 | tags:
5 | - stately
6 | - stately stream
7 | - xstate
8 | - studio
9 | - react
10 | author:
11 | - Farzad Yousefzadeh
12 | publishedAt: "2022-08-31"
13 | ogImage: "https://stately.ai/blog/2022-08-31-building-a-resizable-panel.png"
14 | ---
15 |
16 | Farzad and David add more features to their resizable panel using XState and React. [Watch Part 1](/blog/building-a-resizable-panel).
17 |
18 | [Check out the accompanying code on Code Sandbox](https://codesandbox.io/s/resizable-panel-example-jjgkzl?file=/src/index.tsx).
19 |
20 |
--------------------------------------------------------------------------------
/content/posts/2022-09-14-whats-new-september-2022.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: "What’s new in September 2022?"
3 | description: "The Stately team has got some huge features to share with you soon. Here’s what we’ve been working hard on through the summer!"
4 | tags:
5 | - stately
6 | - xstate
7 | - studio
8 | author:
9 | - Laura Kalbag
10 | publishedAt: "2022-09-14"
11 | ogImage: "https://stately.ai/blog/2022-09-14-whats-new-september-2022.png"
12 | ---
13 |
14 | The Stately team has got some huge features to share with you soon. We’ve been working hard through the summer, which is why we’re already halfway into September by the time I’ve gotten around to this update post.
15 |
16 | ## Human-readable timers
17 |
18 | When building after events, the convention is to specify the delay length in milliseconds, which is great for computers, but less easy for humans to understand. Now we display the timers in more human-friendly terms, including years, weeks, minutes, and seconds. You can still access the delay in milliseconds from the right panel when the event is selected.
19 |
20 | 
21 |
22 | ## New version alerts in the Stately studio
23 |
24 | We will now notify you in the browser when there is a new version of the studio. You’ll likely have seen other platforms with similar notifications in the past. This alert is our way of getting you the latest changes to the studio without the risk of losing your work in progress.
25 |
26 | [Watch the office hours from August 26 for more on the new version alerts](https://youtu.be/HI8LbL5Yu74?t=150).
27 |
28 | ## XState 4.33.6 patch release
29 |
30 | We’re all looking forward to the XState version 5 release. In the meantime, we’ve got some migratory moves towards v5 in the form of the [XState 4.33.6 patch release](https://github.com/statelyai/xstate/releases/tag/xstate%404.33.6).
31 |
32 | Reading state directly from `someService.state` is now deprecated, and we encourage you to use `someService.getSnapshot()` instead. `.getSnapshot()` will become the go-to way to read the current snapshot from any actor.
33 |
34 | We’re also deprecating the `send()` action in favor of the new `sendTo()` action. `sendTo(actorName, event)` allows you to send to a specific, named actor with the `actorName` string. `sendTo()` paves the way for more improved typings and making the terms and concepts we use easier to understand for folks new to XState.
35 |
36 | [Find out more in David’s update on the 4.33.6 patch release from last week’s office hours](https://youtu.be/H0uTQbaW9rk?t=115).
37 |
38 | ## Have you attended our office hours?
39 |
40 | If you want more regular updates from the Stately team, check out the [Stately office hours](https://youtube.com/playlist?list=PLvWgkXBB3dd6PXbSoctwDXjWX-AQrxhds). Every Friday at 10 AM ET, we live stream demos and discussions of our recent work at Stately and on XState. Live streaming on YouTube, Twitter, LinkedIn and Twitch, they’re a real highlight of our week, and we’re nearing our 50th edition 🎉.
41 |
42 | Be sure to join us at [our next office hours this Friday](https://www.youtube.com/watch?v=37YVzAjhDHA)!
--------------------------------------------------------------------------------
/content/posts/2022-10-27-studio-tutorials.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: Learn the Stately Studio with our new video tutorials
3 | description: If you’re new to the Stately Studio, state machines or statecharts, we have the videos for you! Our new Stately Studio tutorials playlist on YouTube features bite-size videos to help you get started with understanding statecharts and state machines, and start modeling in the Stately Studio.
4 | tags:
5 | - editor
6 | - studio
7 | - tutorials
8 | - video
9 | author: Laura Kalbag
10 | ogImage: "https://stately.ai/blog/2022-10-27-studio-tutorials.png"
11 | publishedAt: "2022-10-27"
12 | ---
13 |
14 | If you’re new to the Stately Studio, state machines or statecharts, we have the videos for you! Our new Stately Studio tutorials playlist on YouTube features bite-size videos to help you get started with understanding statecharts and state machines, and start modeling in the Stately Studio.
15 |
16 | Each video explains a concept with an example machine and shows you how to use the features in the Stately Studio. You can [watch the whole playlist](https://www.youtube.com/playlist?list=PLvWgkXBB3dd4I_l-djWVU2UGPyBgKfnTQ) in one go or watch the videos individually, as shown below.
17 |
18 | ## What are state machines and statecharts?
19 |
20 |
21 |
22 | ## States
23 |
24 |
25 |
26 | ## Initial states
27 |
28 |
29 |
30 | ## Transitions and events
31 |
32 |
33 |
34 | ## Parent and child states
35 |
36 |
37 |
38 | ## Parallel states
39 |
40 |
41 |
42 | ## Final states
43 |
44 |
45 |
46 | ## Entry and exit actions
47 |
48 |
49 |
50 | ## Delayed (after) transitions
51 |
52 |
53 |
54 | ## State done events
55 |
56 |
57 |
58 | ## Invoked actors
59 |
60 |
61 |
62 | ## Descriptions
63 |
64 |
65 |
66 | ## More videos coming soon
67 |
68 | We’ll be adding more videos to the playlist very soon! Do you want us to make tutorials for a concept you need help understanding? Or how to use a particular feature in the Stately Studio? [Leave us a request on our Canny roadmap](https://statelyai.canny.io).
69 |
--------------------------------------------------------------------------------
/content/posts/2022-11-22-studio-update.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: 'New in the Studio: Safari support, new login providers, and more!'
3 | description: It’s been just over a month since we released Stately Studio 1.0, and the team has barely slowed down! We’ve got more features live in the Studio today and even more planned before the end of the year.
4 | tags:
5 | - editor
6 | - studio
7 | - safari
8 | - login
9 | - performance
10 | author: Laura Kalbag
11 | ogImage: "https://stately.ai/blog/2022-11-22-studio-update.png"
12 | publishedAt: "2022-11-22"
13 | ---
14 |
15 | It’s been just over a month since [we released Stately Studio 1.0](/blog/stately-studio-1-0/), and the team has barely slowed down! We’ve got more features live in the Studio today and even more planned before the end of the year.
16 |
17 | [Watch a demo of these features in our release video](https://www.youtube.com/watch?v=N9QtPcknqDw).
18 |
19 | ## Safari support
20 |
21 | We’re happy to tell you [the Stately Studio](https://stately.ai/studio) now works in Safari. It took a significant code refactor, which doesn’t just mean that you can now edit your statecharts using Safari; the new code structure should also give us bonuses for accessibility and future integrations. If you’re curious about what David refactored, you can watch him talk about the Safari support during [our office hours from last week](https://youtu.be/JBckQTgeD9g?t=2153).
22 |
23 | Safari support is still in beta, you’ll get a message warning you when you open the Studio in Safari for the first time. Your machines are not in danger; you might encounter a few bugs when using the Safari browser. If you do come across any bugs, please let us know in the #studio-feedback channel in [our Discord](https://discord.gg/xstate), and we’ll try to get them fixed as quickly as possible.
24 |
25 | ## Sign up and log in with Twitter, Google, and email
26 |
27 | You can now log into the Stately Studio with Twitter or Google, or set up an account with your email address and password. We’ve had GitHub login support since we first launched the Studio, and alternative login providers have been a popular request from our community.
28 |
29 | 
30 |
31 | Are there any login providers we should add? Please let us know as a [feature request on our Studio board](https://statelyai.canny.io/studio). Many options are available to us, and we aim to support the community’s most popular providers.
32 |
33 | ## More editor improvements
34 |
35 | We’ve continued making usability improvements to the editor. You might notice that transition lines now run underneath the nodes, resulting in tidier, more readable machines by default. We also now highlight the selected event and its target and source states, fading out other nodes. Changes like this should help you focus and understand the machine, especially inside vast and complex machines.
36 |
37 | 
38 |
39 | ## Better overall performance
40 |
41 | The team has also migrated the Studio to tRPC v10 on the back end and TanStack Query on the front end. The migration isn’t a change you can see, but it has enormously improved the performance of the Studio, making everything feel speedier and smoother.
42 |
43 | ## Want to know what’s coming up?
44 |
45 | If you want to keep up with the team’s latest work-in-progress, [subscribe to our YouTube channel](https://youtube.com/statelyai). We share our work, upcoming features, and answer your questions in our regular office hours live streams. [Check out last week’s office hours live stream](https://www.youtube.com/watch?v=JBckQTgeD9g) for a peek into features we’re looking to release very soon.
46 |
47 | ## Request the features you want
48 |
49 | If you’ve watched [our office hours](https://www.youtube.com/watch?v=JBckQTgeD9g&list=PLvWgkXBB3dd6PXbSoctwDXjWX-AQrxhds), you know the team listens to every feature request and loves to make our community happy. You can request features, upvote other people’s suggestions, and check out what’s in progress on [our Canny roadmap](https://statelyai.canny.io).
--------------------------------------------------------------------------------
/content/posts/2022-11-29-import-from-code.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: 'New in the Studio: Import from code'
3 | description: One of our most-requested features has just landed in the Stately Studio; you can now import from code!
4 | tags:
5 | - editor
6 | - studio
7 | - import
8 | - code
9 | - xstate
10 | author: Laura Kalbag
11 | ogImage: "https://stately.ai/blog/2022-11-29-import-from-code.png"
12 | publishedAt: "2022-11-29"
13 | ---
14 |
15 | One of our most-requested features has just landed in the Stately Studio; you can now import your machines from code!
16 |
17 | [Watch import from code in action in our latest video](https://www.youtube.com/watch?v=DAoIFaugDLo).
18 |
19 | Importing from code is handy if you’ve already built machines while working with [XState](https://xstate.js.org/docs), or have created a machine using our older [Stately Viz](https://stately.ai/viz) and haven’t yet tried the [Stately visual editor](https://stately.ai/editor).
20 |
21 | ### How to import from code
22 |
23 | You can import an existing machine from JavaScript and TypeScript using the code panel in the right tool menu or from the **Machines** list in the left drawer.
24 |
25 | 
26 |
27 | 
28 |
29 | Your code should be formatted as a [`createMachine()` factory function](https://xstate.js.org/docs/guides/machines.html) before import. The importer has basic validation in case your machine has basic errors, including reminding you if the `createMachine` definition is missing.
30 |
31 | 
32 |
33 | And please import your code into an existing machine with caution! Importing code from the code panel will overwrite the current machine in the editor. You may have multiple `createMachine`s included in the code you insert in the text area, but the Studio will currently only import the first machine found in the code. We plan to support importing multiple machines in the future, if that’s a feature you’d love, please [upvote the multiple machine import feature request](https://statelyai.canny.io/editor/p/import-multiple-machines-from-one-code-import) on our board.
34 |
35 | 
36 |
37 | ## Export code
38 |
39 | What about exporting your machines as code? You might have missed this feature as we released it as part of the [Stately Studio 1.0 release](https://stately.ai/blog/introducing-stately-studio-10#more-export-options). You can export your machine as JSON, JavaScript, and TypeScript using the code panel in the right tool menu.
40 |
41 | Using the export icon button in the editor’s top bar, you can also export as code from the **Export machine** dialog. [Check out Laura’s demo utilizing this feature to go from modeling your machine to code](https://www.youtube.com/watch?v=NVQai9SBpiU).
42 |
43 | ## Please give us your feedback!
44 |
45 | Have you used the import and export features yet? We’d love to hear your thoughts! The team loves hearing your feedback [on our Stately Discord](https://discord.gg/xstate) or during our next [office hours live stream](https://youtube.com/statelyai). If you have any feature requests, please add them to our [feature request board](https://statelyai.canny.io), and we’ll keep you updated if it’s planned, in progress, or complete!
--------------------------------------------------------------------------------
/content/posts/2022-12-13-new-in-the-studio-machine-disaster-recovery.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: "New in the Studio: Machine restore"
3 | description: >-
4 | We have introduced a new feature to the Stately Studio, a feature we hope
5 | you’ll never see. Let’s call it machine restore, for lack of a better description.
6 | tags:
7 | - recovery
8 | - restore
9 | - offline
10 | - editor
11 | - studio
12 | author:
13 | - - Anders Bech Mellson
14 | ogImage: "https://stately.ai/blog/2022-12-22-machine-recovery.png"
15 | publishedAt: "2022-12-13"
16 | ---
17 |
18 | We have introduced a new feature to the Stately Studio, a feature we hope you’ll never see. Let’s call it machine restore, for lack of a better description.
19 |
20 | ### What's the challenge?
21 |
22 | At this moment in time, the Studio is using a traditional server-client architecture. Whenever you edit a machine, we will persist these changes to our central database, ready for you to use when you return - on any device with an internet connection.
23 |
24 | 
25 |
26 | But what happens with your edits if your internet connection fails or the Stately backend is having problems? This is where our new feature comes into play.
27 |
28 | ### Example
29 |
30 | In our example, Santa’s delivery machine has a problem; the Christmas-time state is unreachable. So we do as any good Santa’s helper would; we create an event to get to Christmas. But alas, we’re offline, so our changes could get lost. Before this new feature, there was a chance you wouldn’t notice you’d gone offline or that the server returned an error. But as you can see in the GIF below, we’ve introduced new error banners to show you what’s happening.
31 |
32 | 
33 |
34 | ### How to restore
35 |
36 | We try our best to detect any failure or missing connectivity when you edit your machines. If you hit any error state, we will inform you and start saving your work locally on your device. So next time you visit the Studio from that same device, we will compare what we saved with the machine from the server. And if they are different, we will give you the option to restore the safe copy to a new machine.
37 |
38 | You can see this in action using our example from above. When I return to the Studio, I can restore the changes I did while offline. Christmas is saved.
39 |
40 | 
41 |
42 | Hopefully, you’ll never see this feature, but if you do, I hope you find it helpful.
43 |
44 | ### What's next
45 |
46 | We have some exciting plans around an offline-first approach for the Studio which should make this restore feature obsolete and also enable features such as multi-player editing. Stay tuned for more news about this in 2023.
47 |
--------------------------------------------------------------------------------
/content/posts/2022-2-6-stately-editor-public-beta.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: Stately Editor public beta
3 | description: We’re excited to announce the public beta of the Stately Editor! The Stately Editor is a tool for creating and editing state diagrams. We’ve received a lot of great feedback from the private beta testers, and now we’re delighted to share it with everyone.
4 | tags:
5 | - editor
6 | - announcement
7 | - beta
8 | author: David Khourshid
9 | ogImage: "https://stately.ai/blog/2022-02-08-join-the-stately-editor-public-beta.png"
10 | publishedAt: "2022-02-08"
11 | ---
12 |
13 | We’re excited to announce the public beta of the Stately Editor! The Stately Editor is a tool for creating and editing state diagrams. We’ve received a lot of great feedback from the private beta testers, and now we’re delighted to share it with everyone.
14 |
15 | **[Try the Stately Editor beta now](https://stately.ai/editor?source=blog)**
16 |
17 | 
18 |
19 | The software development lifecycle today is a bit fragmented. It’s very difficult for user stories, designs, code, tests, and documentation to stay in sync, leading to parts going out-of-date or even missing entirely. Bugs increase, and adding or modifying features becomes increasingly complex. And even understanding all the features and use-cases of an app becomes a daunting task.
20 |
21 | Our mission is to **make app logic accessible to the entire team**, including developers, designers, and stakeholders. Using state machines and statecharts as a common visual language, the software development cycle becomes more collaborative, eliminating handoff and tightening the feedback loop.
22 |
23 | The Stately Editor aims to be that collaborative visual app logic tool. Before, developers could build state machines and statecharts in code using [XState](https://github.com/statelyai/xstate). Now, you can create those same state diagrams visually.
24 |
25 | And yes, it goes both ways: edit the code and see the updated state diagram. Edit the state diagram and see the updated code in real-time. All this is possible with the [XState VS Code extension](https://marketplace.visualstudio.com/items?itemName=statelyai.stately-vscode).
26 |
27 | ## Features
28 |
29 | The editor supports everything you need to build state machines and statecharts:
30 |
31 | - Atomic, compound, parallel, history, and final states
32 | - Normal, guarded, and delayed events/transitions
33 | - Entry, exit, and transition actions
34 | - Invocations
35 | - Done and error transitions for states and invocations
36 | - State and event descriptions
37 |
38 | There are currently two modes:
39 |
40 | - **Editor mode**: add, modify, and delete states, events, and transitions, as well as data like actions, descriptions, and invocations.
41 | - **Simulation mode**: run the statechart, trigger events, and see the active state nodes.
42 |
43 | You can also **export machines to JSON**, ready to be used in your codebase with XState.
44 |
45 | ## Roadmap
46 |
47 | We have a long list of features planned for the editor, including:
48 |
49 | - Parameterized actions, guards, and invocations
50 | - Built-in actions, such as `assign` and `raise`
51 | - Schema editing for `context` and `events`
52 | - More granular simulation control, such as specifying event payload and simulating delays
53 | - Visualizing systems of actors, including spawned and invoked machines
54 | - Warnings and errors for invalid machine definitions
55 | - Customizable state node, event, and transition colors
56 | - Rich text editing and content for state descriptions
57 | - Markdown generation
58 | - Event recording and playback
59 | - Machine versioning and diffing
60 | - Autolayout and smart layout controls
61 | - Teams and private machines/systems
62 | - _And so much more._
63 |
64 | ## Join the public beta
65 |
66 | Excited to see what the Stately Editor can do? [Join the public beta by registering for free](https://stately.ai/registry?source=blog) and [create your first machine](https://stately.ai/editor?source=blog), or [discover other people’s machines](https://stately.ai/registry/discover?source=blog) and get inspired.
67 |
68 | Please [let us know](https://github.com/statelyai/editor-feedback/issues/new) if you have any feedback, feature requests or bug reports.
69 |
70 |
71 | Try the Stately Editor beta and start modeling your app logic visually.
72 |
73 |
74 | ## Next steps
75 |
76 | The editor is the initial state towards making the ultimate collaborative tool for visually editing even the most complex app logic. We’re excited to share the Stately Editor with the world, and we’re looking forward to hearing your reactions.
77 |
78 | [Join our Discord community](https://discord.gg/xstate) to get help, ask questions, and give us your feedback.
79 |
--------------------------------------------------------------------------------
/content/posts/2023-01-19-introducing-the-stately-docs.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: "Introducing the Stately docs"
3 | description: >-
4 | The time has finally come; our new docs are ready to share with you all. If you’ve been following our office hours, you know I’ve been talking about these docs for a long time…
5 | tags:
6 | - studio
7 | - xstate
8 | - docs
9 | - search
10 | - light mode and dark mode
11 | - contribute
12 | author:
13 | - Laura Kalbag
14 | ogImage: "https://stately.ai/blog/2023-01-19-introducing-the-stately-docs.png"
15 | publishedAt: "2023-01-19"
16 | ---
17 |
18 | The time has finally come; [our new docs](https://stately.ai/docs) are ready to share with you all. If you’ve been following our office hours, you know I’ve been talking about these docs for a long time. Thanks to Anders, who used [Docusaurus](https://docusaurus.io) to build us a rock solid easily-maintainable platform with search that actually works, and the whole team, who have contributed reviews, explainers, and examples to get these docs started.
19 |
20 | 
21 |
22 | ## Docs for the Stately Studio
23 |
24 | Our new docs have documentation for both the [Stately Studio](https://stately.ai/editor) and [XState](https://xstate.js.org). If you want to learn how to use the Studio without having to learn any code, we’ve got you covered with a [no-code introduction to state machines and statecharts](https://stately.ai/docs/state-machines-and-statecharts) and [step-by-step tutorials for different features in the Studio](https://stately.ai/docs/states/intro). We’ve also got a [modeling section](https://stately.ai/docs/descriptions) where we’ll add more guides to modeling your machines in the future.
25 |
26 | ## Docs for XState
27 |
28 | If you’re a more experienced developer who wants to [jump straight into XState](https://stately.ai/docs/xstate/basics/what-is-a-statechart), we have docs that focus on the coding experience and cover all the concepts you need to know when working with XState. Shoutout to [Matt Pocock](https://totaltypescript.com), who used his vast knowledge of XState to kick these docs off when he was with us last year.
29 |
30 | 
31 |
32 | ## Useful search
33 |
34 | As I mentioned earlier, the search in the docs really works. Search is a problem for a lot of documentation across the web and something we were keen to improve over the previous XState docs. Anders worked hard to make the Algolia search work for us, and while the structure of our docs navigation is essential, we all know the search is where you’ll likely go first.
35 |
36 | 
37 |
38 | ## Dark mode
39 |
40 | One of our most-requested features for our docs was dark mode. Inspired by Nick’s light and dark mode designs for the Studio, I’ve given the docs light mode and dark modes that should hopefully be easy on the eyes and give you the best possible reading experience. Even our images respond to the light and dark modes!
41 |
42 | 
43 |
44 | ## Easy to contribute
45 |
46 | At the end of every page, we have an **Edit this page on GitHub** link, which takes you directly to that page in our docs’ GitHub repository. We appreciate any contributions that help our community learn XState and the Stately Studio. We have a short [Stately Guide to Writing Docs wiki](https://github.com/statelyai/docs/wiki) on [our repository](https://github.com/statelyai/docs/) with recommendations on structure and style. Read below if you want to suggest an improvement to our docs.
47 |
48 | 
49 |
50 | ## Still in beta
51 |
52 | These docs are still in beta, and we want your feedback! At Stately, we care a great deal about accessible and valuable education. Our docs are a living iterable product, and we want to continuously improve them to make them as valuable a resource as possible. Please [let us know in Discord](https://discord.gg/xstate) or [on Twitter](https://twitter.com/statelyai) if you have suggestions for improvements or where we could make the docs clearer or better for you. Use [our Canny documentation request board](https://statelyai.canny.io/docs) if you have a page, feature, or example request.
53 |
54 | We hope you like our new, improved docs, and we’re looking forward to hearing from you!
--------------------------------------------------------------------------------
/content/posts/2023-02-06-github-import-machines.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: "Import machines from GitHub"
3 | description: Learn about a new pro feature in the Stately Studio; importing machines from GitHub.
4 | tags:
5 | - stately
6 | - studio
7 | - integration
8 | - github
9 | author:
10 | - Anders Bech Mellson
11 | publishedAt: "2023-02-06"
12 | ogImage: "https://stately.ai/blog/2023-02-06-github-import-machines.png"
13 | ---
14 |
15 | Today we’re happy to introduce another pro feature for our Stately Studio subscribers; **import machines from GitHub**. With this feature, you can quickly visually machines in any of your GitHub repositories. You can even import the machines to the Studio and keep working on them here 🎉
16 |
17 | ## How to
18 |
19 | Importing a machine is easy. You open a file containing one or more machines on GitHub. Next, you modify the URL, replace `.com` with `.stately.ai`, and the import will start.
20 |
21 | 
22 |
23 | ### Example
24 |
25 | If you have a machine hosted at GitHub: `https://github.com/username/repo/blob/main/apps/superMachine.ts`, you update the URL to `https://github.stately.ai/username/repo/blob/main/apps/superMachine.ts` and the import will start 🚀
26 |
27 | ### Saving the machine
28 |
29 | You can easily save imported machines into a Studio project. After the import, you click the save button and choose a project for the machine.
30 |
31 | 
32 |
33 | ## Get started
34 |
35 | This feature requires the following prerequisites:
36 |
37 | - A **professional or enterprise** subscription to the Stately Studio.
38 | - You must install the GitHub integration app.
39 |
40 | When importing a machine, we help you with both of those tasks.
41 |
42 | Your GitHub token is stored on your own devices by design; we don’t save it in our database. This is to keep your data as safe as possible with the tradeoff being that you must accept the integration on the initial import for each device you use.
43 |
44 | See this example where the GitHub integration gets installed during the initial import.
45 |
46 | 
47 |
48 | ## Future work
49 |
50 | We have much more planned for integrating with GitHub; this is just the start. Let us know what you think about the machine import and what GitHub integration features you would like to see in the Stately Studio.
51 |
52 | ### Bookmarklet bonus
53 |
54 | You can create a [bookmarklet](https://en.wikipedia.org/wiki/Bookmarklet) if you want to make it extra easy to import machines from GitHub. You do this by adding a new bookmark and setting the web address to `javascript:(function(){ location.href = 'https://github.stately.ai/' + window.location.pathname;})();`. Now you can click the bookmarklet whenever you want to import a machine. The bookmarklet will work on any GitHub file containing one or more machines.
55 |
--------------------------------------------------------------------------------
/content/posts/2023-03-09-import-all-machines-from-github-repo.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: "Import all machines from your GitHub repo"
3 | description: Learn about a new pro feature in the Stately Studio; importing all your machines from a GitHub repo.
4 | tags:
5 | - stately
6 | - studio
7 | - integration
8 | - github
9 | author:
10 | - Laura Kalbag
11 | publishedAt: "2023-03-09"
12 | ogImage: "https://stately.ai/blog/2023-03-09-import-all-machines-from-github-repo.png"
13 | ---
14 |
15 | Last month, Anders showed you how you could [import a machine from GitHub by changing the GitHub URL in the browser’s address bar](/import-machines-from-github). We’ve added more to our GitHub integration. Our [Pro](https://stately.ai/pricing) users can now import all the machines from a repository into a Stately Studio project with the **Import from GitHub** button.
16 |
17 | 
18 |
19 | If you’ve been working with state machines in XState or using the [XState VS Code extension](https://marketplace.visualstudio.com/items?itemName=statelyai.stately-vscode) to visualize your machines, this is a great way to import all the machines in your repo quickly. Once you’ve imported your machines into the Stately Studio, you can visualize and improve them in our Editor and easily share your machines with your team.
20 |
21 | ## How to import all the machines from a GitHub repository
22 |
23 | 1. Navigate to **My Projects** from the sidebar or the Stately menu.
24 | 2. Use **Import from GitHub** to open the Import repo from GitHub modal.
25 | 3. The GitHub integration will fetch all available repositories (public and private).
26 | 4. Choose the repository from which you wish to import machines.
27 | 5. The Studio will import your machines into a new private project using the same name as your repository and open your project in the Editor.
28 |
29 | Importing a machine with **Import from GitHub** or importing a machine with a GitHub URL will prompt you to **Allow integration** to give our GitHub integration access to your GitHub repositories. You will only be prompted if you have not yet given the GitHub integration access on your current device.
30 |
31 | Currently, the **Import from GitHub** feature imports all machines from the *default branch* in your GitHub repository. If you want to import machines from a different branch or a pull request, we recommend [importing each machine from a GitHub URL](/import-machines-from-github).
32 |
33 | ## Try our Pro plan to import from GitHub
34 |
35 | Import from GitHub is one of the [Pro features](https://stately.ai/docs/studio-pro-plan) of the Stately Studio. We offer a **30-day free trial** on the [Stately Studio Pro account](https://stately.ai/pricing) so you can explore how our Pro features work for you and your team today!
36 |
--------------------------------------------------------------------------------
/content/posts/2023-04-03-book-a-demo.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: "Book a demo with the Stately team"
3 | description: Are you looking to take your team collaboration to the next level? Do you want to explore the features of Stately and XState to their fullest potential? Then book a live demo with the Stately team!
4 | tags:
5 | - stately
6 | - studio
7 | - demo
8 | - xstate
9 | author:
10 | - Laura Kalbag
11 | publishedAt: "2023-04-03"
12 | ogImage: "https://stately.ai/blog/2023-04-03-book-a-demo.png"
13 | ---
14 |
15 | Are you looking to take your team collaboration to the next level? Do you want to explore the features of Stately and XState to their fullest potential? Then book a live demo with the Stately team!
16 |
17 | Our team is excited to give you a walkthrough of the Stately Studio and explore your use cases. During the demo, you can get answers to all your questions about Stately and XState. Learning more about you and your team will help us develop future features that benefit your work.
18 |
19 | What can you expect from a live demo with the Stately team?
20 |
21 | ## Walkthrough of the Stately Studio
22 |
23 | Get an in-depth tour of Stately’s visual editor and its features. Explore how the Stately Studio works for teams and learn how to build complex state machines quickly.
24 |
25 | ## Explore your use cases
26 |
27 | Our team will help you explore the Stately Studio’s features by walking you through your use cases. We can help you understand how Stately can be used to solve your specific problems and how you can integrate it into your workflow.
28 |
29 | ## Answer any questions you have about Stately and XState
30 |
31 | During the demo, our team will answer your questions about Stately and XState. Whether you’re curious about a particular feature or want to know how Stately can help you solve a specific problem, our team will provide the answers you need.
32 |
33 | ## Follow-up demo designed for your team and use cases
34 |
35 | After the demo, our team can work with you to schedule a follow-up demo that is designed specifically for your team and use cases. We will consider your feedback from the initial demo and create a customized demo that meets your specific needs.
36 |
37 |
38 | Use the link below to book your live demo. We look forward to helping you build amazing applications with Stately and XState.
39 |
--------------------------------------------------------------------------------
/content/posts/2023-05-03-introducing-state-new.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: "Introducing ➡️ state . new"
3 | description: We're making it even easier to create state diagrams with our new domain state.new.
4 | tags:
5 | - stately
6 | - studio
7 | - state diagrams
8 | - state charts
9 | - state machines
10 | - create
11 | author:
12 | - Anders Bech Mellson
13 | publishedAt: "2023-05-03"
14 | slug: introducing-state-new
15 | ogImage: "https://stately.ai/blog/2023-05-03-introducing-state-new.png"
16 | ---
17 |
18 | Our top priority at Stately is to make it as easy as possible to create robust app logic in the form of state diagrams. That’s why we’re constantly striving to remove any potential barriers.
19 |
20 | ## What’s the problem?
21 |
22 | One barrier we’ve identified is; **where to start when you want to create a state diagram?** Well, as some of you might have noticed from David’s tweet the other day, we now have a solution for this.
23 |
24 | We’re excited to share that generating a new diagram has never been easier. Simply input [`state.new`](https://state.new) into your browser, and you can edit your brand-new diagram immediately.
25 |
26 |
27 |
28 | _By the way_, that tweet caused quite a splash. At this point in time it has over 1.5K likes and around 250K views. We also got a big spike of new users and are thrilled to have you!
29 |
30 | State machines, charts and diagrams might be old, but luckily never go out of fashion!
31 |
32 | ## Why state.new?
33 |
34 | Sorry for being captain obvious here, but we think state.new is the perfect domain for creating a new state. A new state diagram, a new state machine, even a new state of mind, perhaps if you haven’t used machines and state diagrams for your app logic before. Give it a try, and let us know what you think.
35 |
36 | ## What does it look like?
37 |
38 | When you land in the editor for the first time, you’ll find an example diagram to familiarize you with the concepts. You’re free to edit and delete this starting point to your liking. Notice that we have a little blue helper button in the bottom-right corner which you can click to [learn more about creating state diagrams](./learn-the-stately-studio-with-our-new-video-tutorials).
39 |
40 | 
41 |
42 | We can’t wait to see what you create!
43 |
--------------------------------------------------------------------------------
/content/posts/2023-05-12-office-hours-64.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: "Watch our “best Stately office hours yet”"
3 | description: Two weeks ago we had what some have called our “best office hours yet.” Watch the video to find out what’s coming soon to Stately Studio.
4 | tags:
5 | - stately
6 | - studio
7 | - office hours
8 | - starter machine
9 | - annotations
10 | - embed mode
11 | - version history
12 | - blocks
13 | - xstate
14 | - xstate v5
15 | - changelog
16 | author:
17 | - Laura Kalbag
18 | publishedAt: "2023-05-12"
19 | slug: office-hours-64
20 | ogImage: "https://stately.ai/blog/2023-05-12-office-hours-64.png"
21 | ---
22 |
23 | Two weeks ago, we had what some have called our “best office hours yet.” We introduced a whole bunch of new features and improvements to Stately Studio, including [state.new](https://state.new?source=blog) with our new starter machine, annotations, embed mode, and version history. We also gave the first peek at our most significant editor update to date; we call it “codename: blocks,” check out the video to find out why!
24 |
25 | We also talk about XState v5 being in beta (more on that soon!) and [how to migrate from XState V4 to V5](https://stately.ai/docs/xstate-v5/migration).
26 |
27 |
28 |
29 | Watch the video to find out what’s coming soon to Stately Studio. Use the links below to jump straight to that chapter in the video:
30 |
31 | - [0:00:00 Intro](https://www.youtube.com/watch?v=FY030no59Y4&t=0s)
32 | - [0:00:10 Team intros](https://www.youtube.com/watch?v=FY030no59Y4&t=10s)
33 | - [0:02:02 state.new 🆕](https://www.youtube.com/watch?v=FY030no59Y4&t=122s)
34 | - [0:02:20 New default machine](https://www.youtube.com/watch?v=FY030no59Y4&t=140s)
35 | - [0:02:30 Annotations 🆕](https://www.youtube.com/watch?v=FY030no59Y4&t=150s)
36 | - [0:05:08 Embed mode 🆕](https://www.youtube.com/watch?v=FY030no59Y4&t=308s)
37 | - [0:10:47 Version history 🆕](https://www.youtube.com/watch?v=FY030no59Y4&t=647s)
38 | - [0:19:31 Deletion confirmation 🆕](https://www.youtube.com/watch?v=FY030no59Y4&t=1171s)
39 | - [0:20:51 Codename: blocks (coming soon)](https://www.youtube.com/watch?v=FY030no59Y4&t=1251s)
40 | - [0:27:57 Codename: blocks continued… colors! (coming soon)](https://www.youtube.com/watch?v=FY030no59Y4&t=1677s)
41 | - [0:31:12 Codename: blocks as machine options (coming soon)](https://www.youtube.com/watch?v=FY030no59Y4&t=1872s)
42 | - [0:49:40 XState v5 (in beta)](https://www.youtube.com/watch?v=FY030no59Y4&t=2980s)
43 | - [0:53:42 Use cases for XState in the backend](https://www.youtube.com/watch?v=FY030no59Y4&t=3222s)
44 | - [0:55:29 Changelog 🆕](https://www.youtube.com/watch?v=FY030no59Y4&t=3329s)
45 | - [0:57:11 Remote inspect via websockets](https://www.youtube.com/watch?v=FY030no59Y4&t=3431s)
46 | - [0:58:49 Detecting the version of XState you’re using](https://www.youtube.com/watch?v=FY030no59Y4&t=3529s)
47 | - [0:59:38 Wrap up](https://www.youtube.com/watch?v=FY030no59Y4&t=3578s)
48 |
49 | You can join us for our [next office hours live today at 10 AM ET](https://www.youtube.com/watch?v=fPrZ19EKlJU). We’ll share more demos and take your questions live; we hope to see you there!
--------------------------------------------------------------------------------
/content/posts/2023-05-16-stately-streams.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: "Watch in-depth demos in our Stately Streams"
3 | description: Tomorrow is part four in our popular Stately Stream series, where we are modeling a semi-complex client-side application using XState, Stately Studio, React and TypeScript.
4 | tags:
5 | - stately
6 | - studio
7 | - xstate
8 | - xstate v5
9 | - stately stream
10 | - demo
11 | - examples
12 | author:
13 | - Farzad Yousefzadeh
14 | publishedAt: "2023-05-16"
15 | slug: stately-streams-may-2023
16 | ogImage: "https://stately.ai/blog/2023-05-16-stately-streams.png"
17 | ---
18 |
19 | [Tomorrow is part four in our popular Stately Stream series](https://www.youtube.com/watch?v=sigMw-Xelvw), where we are modeling a semi-complex client-side app using XState, Stately Studio, React and TypeScript. You can catch up on the previous videos in the series below or [watch all our past videos in our Stately Streams YouTube playlist](https://www.youtube.com/playlist?list=PLvWgkXBB3dd5UEJZCk4C3Wn1Ys8WRMDbi).
20 |
21 | Across this series, David and I have been working on a canvas-based app project that showcases using statecharts for both components and globally accessible actors across an entire system, as well as multi-actor communication and state orchestration.
22 |
23 | ## Part 1
24 |
25 | In part 1 we look at the power of using statecharts to model and implement a canvas-based app.
26 |
27 |
28 |
29 | ## Part 2
30 |
31 | In part 2, we look at implementing multiple selection, including collision detection and what you might need for live collaboration.
32 |
33 |
34 |
35 | ## Part 3
36 |
37 | In part 3, we migrate our code from XState V4 to [XState V5](https://stately.ai/xstate-v5/migrate).
38 |
39 |
40 |
41 | ## Watch part 4 tomorrow at 6.30 PM ET
42 |
43 | Join us tomorrow at 6.30 PM ET on YouTube or [LinkedIn](https://www.linkedin.com/events/statelystream-modelingagraphica7064177817600581634/) for our next live stream!
44 |
45 |
--------------------------------------------------------------------------------
/content/posts/2023-05-18-explain-your-machines-with-annotations.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: "Explain your machines with annotations"
3 | description: Sometimes you want to share a machine with descriptive details or comments, so we’ve added annotations to Stately Studio.
4 | tags:
5 | - stately
6 | - studio
7 | - annotations
8 | - comments
9 | - teams
10 | author:
11 | - Laura Kalbag
12 | publishedAt: "2023-05-18"
13 | slug: explain-your-machines-with-annotations
14 | ogImage: "https://stately.ai/blog/2023-05-18-explain-your-machines-with-annotations.png"
15 | ---
16 |
17 | Sometimes you want to share a machine with descriptive details or comments, so we’ve added [annotations](https://stately.ai/docs/annotations) to Stately Studio.
18 |
19 | Unlike [descriptions](https://stately.ai/docs/descriptions), annotations are notes you can use to annotate your machine that only appear in Stately Studio’s editor. To add an annotation, right-click anywhere on the canvas to bring up the canvas menu and use **Add annotation** to add your annotation.
20 |
21 | [Check out the dog walk machine below](https://stately.ai/registry/editor/embed/5b170468-d66a-4136-84c8-676c8fea82e8?machineId=7879be19-d267-4e75-9a7d-6a870d540257), which I’ve annotated with notes describing the machine and how some of the states work.
22 |
23 |
24 |
25 | *You can now also [embed your machines anywhere `iframe`s are supported](https://stately.ai/docs/xstate-v5/embed)!*
26 |
27 | Annotations are not exported when you [export your machine as code](https://stately.ai/docs/export-as-code), so you can add as many as you like without affecting your codebase!
28 |
29 | Annotations are particularly useful when you’re sharing machines with your teams. [Teams](https://stately.ai/docs/teams) are a pro feature of Stately Studio, where you can share and collaborate on your app logic. We offer a **30-day free trial** on the [Stately Studio Pro account](https://stately.ai/pricing) so you can explore how our Pro features work for you and your team.
30 |
31 | We hope annotations make sharing a link to your machine even easier without additional supporting information or explanation. Try them out today and see how they can enhance your workflow!
32 |
--------------------------------------------------------------------------------
/content/posts/2023-1-27-making-state-machines-global-in-react.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: Making state machines global in React
3 | description: Learn how to use the `createActorContext` function to make state machines global in React.
4 | tags:
5 | - react
6 | - hook
7 | - tutorial
8 | author:
9 | - David Khourshid
10 | originalURL: ""
11 | excerpt: ""
12 | ogImage: "https://stately.ai/blog/2023-1-27-making-state-machines-global-in-react.png"
13 | publishedAt: "2023-01-27"
14 | ---
15 |
16 | React developers often need to share state between components. While the `useMachine(...)` hook provides a convenient way to represent local state as a state machine, it’s not very feasible for shared or global state. Thankfully, `@xstate/react`’s `createActorContext(machine)` function, released in `@xstate/react@3.1.0`, is a convenient way to share state machines globally in any React application.
17 |
18 | The `createActorContext(machine)` function returns a [React Context object](https://beta.reactjs.org/learn/passing-data-deeply-with-context) that interprets the machine and makes the actor (interpreted machine) available through React Context. The object returned from `createActorContext(...)` has helper methods for accessing state and the actor ref. It takes one argument, `machine`, which is a state machine from `createMachine(...)` or a function that lazily returns a machine.
19 |
20 | [▶️ Stately Stream: Simple React todo app with `createActorContext`](https://www.youtube.com/watch?v=M6KjEogxfQE)
21 |
22 | ## Creating an actor context
23 |
24 | Here’s how you would create a React Context for an actor created from a machine and provide it in app scope:
25 |
26 | ```tsx
27 | // ./App.tsx
28 | import { createActorContext } from "@xstate/react";
29 | import { someMachine } from "../path/to/someMachine";
30 |
31 | // Create a React Context for the actor
32 | export const SomeMachineContext = createActorContext(someMachine);
33 |
34 | // ...
35 |
36 | function App() {
37 | return (
38 | // Provide the actor context in app scope
39 |
40 |
41 |
42 | );
43 | }
44 | ```
45 |
46 | This provider will make the actor available to any component that consumes it. You can also provide the actor context in any part of the component tree, such as a modal or a sidebar.
47 |
48 | ## Consuming the actor context
49 |
50 | To consume the actor in a component, you can use the `useActor()` hook to get the `state` and `send` function, or you can use `useSelector(selector, compare?)` hook to derive a specific value from the snapshot:
51 |
52 | ```tsx
53 | // ./SomeComponent.tsx
54 | import { SomeMachineContext } from "./App";
55 |
56 | function SomeComponent() {
57 | // Read full snapshot and get `send` function from `useActor()`
58 | const [state, send] = SomeMachineContext.useActor();
59 | // Or derive a specific value from the snapshot with `useSelector()`
60 | const count = SomeMachineContext.useSelector((state) => state.context.count);
61 |
62 | return (
63 |
64 |
Count: {count}
65 |
66 |
67 | );
68 | }
69 | ```
70 |
71 | As a reminder, the `useSelector(...)` hook is better when you want to control rerenders, as it will only rerender when the selected state changes.
72 |
73 | If you only need the `actorRef`, which is a reference to the invoked actor, you can use the `useActorRef()` hook:
74 |
75 | ```tsx
76 | import { SomeMachineContext } from "./App";
77 |
78 | function SomeComponent() {
79 | const actorRef = SomeMachineContext.useActorRef();
80 |
81 | return (
82 |