File tree Expand file tree Collapse file tree 13 files changed +283
-39
lines changed Expand file tree Collapse file tree 13 files changed +283
-39
lines changed Original file line number Diff line number Diff line change 660
660
}
661
661
662
662
.markdown h1 , .markdown h1 : first-child , .index-page h1 {
663
- --ifm-h1-font-size : 2.5 rem ;
663
+ --ifm-h1-font-size : 1.875 rem ;
664
664
}
665
665
666
666
h2 {
@@ -781,7 +781,7 @@ a:hover {
781
781
article ,
782
782
.index-page {
783
783
margin : 0 auto;
784
- max-width : 66 ch ;
784
+ max-width : 50 rem ;
785
785
}
786
786
787
787
/* back to top button */
@@ -1077,7 +1077,7 @@ html [class*='toggleButton'] {
1077
1077
1078
1078
.theme-doc-sidebar-item-category-level-1 a ,
1079
1079
.theme-doc-sidebar-item-link-level-1 a {
1080
- color : var (--st-text );
1080
+ color : var (--ifm-color-emphasis-0 );
1081
1081
}
1082
1082
1083
1083
.theme-doc-sidebar-item-category-level-1 ul li ,
Original file line number Diff line number Diff line change @@ -524,7 +524,29 @@ const countMachine = createMachine({
524
524
525
525
## TypeScript
526
526
527
- _ Coming soon_
527
+ You can strongly type the ` actions ` of your machine in the ` types.actions ` property of the machine config.
528
+
529
+ ``` ts
530
+ const machine = createMachine ({
531
+ types: {} as {
532
+ // highlight-start
533
+ actions:
534
+ | {
535
+ type: ' track' ;
536
+ params: {
537
+ response: string ;
538
+ };
539
+ }
540
+ | { type: ' increment' ; params: { value: number } };
541
+ // highlight-end
542
+ },
543
+ // ...
544
+ entry: [
545
+ { type: ' track' , params: { response: ' good' } },
546
+ { type: ' increment' , params: { value: 1 } },
547
+ ],
548
+ });
549
+ ```
528
550
529
551
## Cheatsheet
530
552
Original file line number Diff line number Diff line change @@ -413,7 +413,39 @@ function Component(props: { actor?: AnyActorRef }) {
413
413
414
414
## TypeScript
415
415
416
- _ Coming soon_
416
+ You can strongly type the ` actors ` of your machine in the ` types.actors ` property of the machine config.
417
+
418
+ ``` ts
419
+ const fetcher = fromPromise (
420
+ async ({ input }: { input: { userId: string } }) => {
421
+ const user = await fetchUser (input .userId );
422
+
423
+ return user ;
424
+ },
425
+ );
426
+
427
+ const machine = createMachine ({
428
+ types: {} as {
429
+ // highlight-start
430
+ actors: {
431
+ src: ' fetchData' ; // src name (inline behaviors ideally inferred)
432
+ id: ' fetch1' | ' fetch2' ; // possible ids (optional)
433
+ logic: typeof fetcher ;
434
+ };
435
+ // highlight-end
436
+ },
437
+ invoke: {
438
+ src: ' fetchData' , // strongly typed
439
+ id: ' fetch2' , // strongly typed
440
+ onDone: {
441
+ actions : ({ event }) => {
442
+ event .output ; // strongly typed as { result: string }
443
+ },
444
+ },
445
+ input: { userId: ' 42' }, // strongly typed
446
+ },
447
+ });
448
+ ```
417
449
418
450
## Cheatsheet
419
451
Original file line number Diff line number Diff line change @@ -151,13 +151,22 @@ feedbackActor.send({
151
151
152
152
## TypeScript
153
153
154
+ You can strongly type the ` context ` of your machine in the ` types.context ` property of the machine config.
155
+
154
156
``` ts
155
157
const machine = createMachine ({
156
- schema: {} as {
158
+ types: {} as {
159
+ // highlight-start
157
160
context: {
158
161
feedback: string ;
159
162
rating: number ;
160
163
};
164
+ // highlight-end
165
+ },
166
+ // Initial context
167
+ context: {
168
+ feedback: ' ' ,
169
+ rating: 5 ,
161
170
},
162
171
entry : ({ context }) => {
163
172
context .feedback ; // string
Original file line number Diff line number Diff line change @@ -72,14 +72,14 @@ Delayed transitions have a default time interval of 500ms (0.5 seconds).
72
72
73
73
1 . Select the event you want to replace with a delayed transition.
74
74
1 . Right-click the event to open the edit menu.
75
- 2 . From the ** Event type** options, choose ** After** to turn the event into a delayed transition.
75
+ 1 . From the ** Event type** options, choose ** After** to turn the event into a delayed transition.
76
76
77
77
#### Using the transition Details panel
78
78
79
79
1 . Open the transition <Info size = { 18 } /> ** Details** panel from the right tool menu.
80
80
2 . From the ** Event type** dropdown menu, choose ** After** to turn the event into a delayed transition.
81
81
82
- #### Specify delay time
82
+ #### Specify delay time
83
83
84
84
Your delay time interval will be displayed in a human-readable format on hover. For example, 15000ms will be displayed as 15 seconds.
85
85
@@ -160,7 +160,36 @@ Delayed transition timers are canceled when the state is exited.
160
160
161
161
## TypeScript
162
162
163
- _ Coming soon_
163
+ You can strongly type the ` delays ` of your machine in the ` types.delays ` property of the machine config.
164
+
165
+ ``` ts
166
+ const machine = createMachine ({
167
+ types: {} as {
168
+ // highlight-start
169
+ delays: ' shortTimeout' | ' longTimeout' | ' eventually' ;
170
+ // highlight-end
171
+ // ...
172
+ },
173
+ // ...
174
+ after: {
175
+ // Autocompleted
176
+ shortTimeout: {
177
+ /* ... */
178
+ },
179
+ },
180
+ on: {
181
+ someEvent: {
182
+ actions: raise (
183
+ { type: ' anotherEvent' },
184
+ {
185
+ // Autocompleted
186
+ delay: ' eventually' ,
187
+ },
188
+ ),
189
+ },
190
+ },
191
+ });
192
+ ```
164
193
165
194
## Cheatsheet
166
195
Original file line number Diff line number Diff line change @@ -26,7 +26,10 @@ Eventless transitions are labeled “always” and often referred to as “alway
26
26
}
27
27
```
28
28
29
- <SkipDownLink text = " Jump to learning more about eventless transitions in XState" link = " #eventless-transitions-and-guards" />
29
+ <SkipDownLink
30
+ text = " Jump to learning more about eventless transitions in XState"
31
+ link = " #eventless-transitions-and-guards"
32
+ />
30
33
31
34
## Using eventless transitions in Stately Studio
32
35
@@ -77,7 +80,24 @@ Coming soon… examples
77
80
78
81
## TypeScript
79
82
80
- _ Coming soon_
83
+ Eventless transitions can potentially be enabled by any event, so the ` event ` type is the union of all possible events.
84
+
85
+ ``` ts
86
+ const machine = createMachine ({
87
+ types: {} as {
88
+ events: { type: ' greet' ; message: string } | { type: ' submit' };
89
+ },
90
+ // ...
91
+ always: {
92
+ actions : ({ event }) => {
93
+ event .type ; // 'greet' | 'submit'
94
+ },
95
+ guard : ({ event }) => {
96
+ event .type ; // 'greet' | 'submit'
97
+ },
98
+ },
99
+ });
100
+ ```
81
101
82
102
## Cheatsheet
83
103
Original file line number Diff line number Diff line change @@ -167,25 +167,7 @@ console.log(feedbackActor..getSnapshot().hasTag('visible'));
167
167
// logs true
168
168
```
169
169
170
- ### Using tags in Stately Studio
171
-
172
- You can add tags to states and events in Stately Studio.
173
-
174
- First, select the state or event you want to tag.
175
-
176
- #### On the canvas
177
-
178
- 1 . Use the <Plus size = { 18 } /> plus icon button to open the edit menu.
179
- 2 . Choose <Tag size = { 18 } /> ** Tag** from the menu to add a tag block.
180
- 3 . Write your tag’s name in the tag’s text input.
181
- 4 . Use the <PlusSquare size = { 18 } /> plus icon button alongside your recent tag to add more tags.
182
-
183
- #### Using the event details panel
184
-
185
- 1 . Open the state or event <Info size = { 18 } /> ** Details** panel from the right tool menu.
186
- 2 . Use the ** + Tag** button to add a tag block.
187
- 3 . Write your tag’s name in the tag’s text input.
188
- 4 . Use the <PlusSquare size = { 18 } /> plus icon button alongside your recent tag to add more tags.
170
+ Read more about [ tags] ( tags.mdx ) .
189
171
190
172
## Meta
191
173
Original file line number Diff line number Diff line change @@ -235,7 +235,31 @@ on: {
235
235
236
236
## TypeScript
237
237
238
- _ Coming soon_ .
238
+ You can strongly type the ` guards ` of your machine in the ` types.guards ` property of the machine config.
239
+
240
+ ``` ts
241
+ const machine = createMachine ({
242
+ types: {} as {
243
+ // highlight-start
244
+ guards:
245
+ | {
246
+ type: ' isGreaterThan' ;
247
+ params: {
248
+ count: number ;
249
+ };
250
+ }
251
+ | { type: ' isAllowed' };
252
+ // highlight-end
253
+ },
254
+ // ...
255
+ on: {
256
+ event: {
257
+ guard: { type: ' isGreaterThan' , params: { count: 5 } },
258
+ // ...
259
+ },
260
+ },
261
+ });
262
+ ```
239
263
240
264
## Cheatsheet
241
265
Original file line number Diff line number Diff line change @@ -253,16 +253,36 @@ const Component = (props) => {
253
253
254
254
## TypeScript
255
255
256
+ You can strongly type the ` input ` of your machine in the ` types.input ` property of the machine config.
257
+
256
258
``` ts
257
259
import { createActor , createMachine } from ' xstate' ;
258
260
259
261
const machine = createMachine ({
260
262
types: {} as {
263
+ // highlight-start
261
264
input: {
262
265
userId: string ;
263
266
defaultRating: number ;
264
267
};
265
- // ...
268
+ // highlight-end
269
+ context: {
270
+ userId: string ;
271
+ feedback: string ;
272
+ rating: number ;
273
+ };
274
+ },
275
+ context : ({ input }) => ({
276
+ userId: input .userId ,
277
+ feedback: ' ' ,
278
+ rating: input .defaultRating ,
279
+ }),
280
+ });
281
+
282
+ const actor = createActor (machine , {
283
+ input: {
284
+ userId: ' 123' ,
285
+ defaultRating: 5 ,
266
286
},
267
287
});
268
288
```
Original file line number Diff line number Diff line change @@ -37,6 +37,7 @@ Stately Studio’s editor supports everything you need to visually build state m
37
37
You can access quick start tutorials from the blue <HelpCircle size = { 12 } /> Help button in the editor.
38
38
39
39
When you first visit the Editor, you’ll be shown two short videos (7m36s) as a quick start guide. You can access these videos again anytime from:
40
+
40
41
- Editor menu > Help > <GraduationCap size = { 12 } /> ** Learn Stately** .
41
42
- The <HelpCircle size = { 12 } /> Help button > <GraduationCap size = { 12 } /> ** Learn Stately** .
42
43
You can’t perform that action at this time.
0 commit comments