Skip to content

Commit 7653ee3

Browse files
authored
Use snapshot.status === 'done' instead of snapshot.done (#247)
1 parent b75ce3f commit 7653ee3

File tree

1 file changed

+52
-8
lines changed

1 file changed

+52
-8
lines changed

docs/migration.mdx

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ const machine = createMachine({
683683
},
684684
},
685685
},
686-
})
686+
});
687687
```
688688

689689
</TabItem>
@@ -709,7 +709,7 @@ const machine = createMachine({
709709
},
710710
},
711711
},
712-
})
712+
});
713713
```
714714

715715
</TabItem>
@@ -728,15 +728,15 @@ const machine = createMachine({
728728
1000: {
729729
target: 'compoundState.childState',
730730
reenter: true, // make it external explicitly!
731-
}
731+
},
732732
},
733733
initial: 'childState',
734734
states: {
735735
childState: {},
736736
},
737737
},
738738
},
739-
})
739+
});
740740
```
741741

742742
</TabItem>
@@ -753,15 +753,15 @@ const machine = createMachine({
753753
1000: {
754754
// implicitly external
755755
target: 'compoundState.childState', // non-relative target
756-
}
756+
},
757757
},
758758
initial: 'childState',
759759
states: {
760760
childState: {},
761761
},
762762
},
763763
},
764-
})
764+
});
765765
```
766766

767767
</TabItem>
@@ -828,7 +828,7 @@ const machine = createMachine({
828828
},
829829
},
830830
},
831-
})
831+
});
832832
```
833833
834834
</TabItem>
@@ -1121,7 +1121,6 @@ Breaking change
11211121
11221122
To produce output data from a machine which reached its final state, use the `output` property instead of `data`:
11231123
1124-
11251124
<Tabs>
11261125
<TabItem value="v5" label="XState v5 beta">
11271126
@@ -1439,6 +1438,51 @@ actor.batch(events);
14391438
14401439
**Pre-migration tip:** Update v4 projects to loop over events to send them as a batch.
14411440
1441+
### Use `snapshot.status === 'done'` instead of `snapshot.done`
1442+
1443+
:::breakingchange
1444+
1445+
Breaking change
1446+
1447+
:::
1448+
1449+
The `snapshot.done` property, which was previously in the snapshot object of state machine actors, is removed. Use `snapshot.status === 'done'` instead, which is available to all actors:
1450+
1451+
<Tabs>
1452+
1453+
<TabItem value="v5" label="XState v5 beta">
1454+
1455+
```ts
1456+
//
1457+
const actor = createActor(machine);
1458+
actor.start();
1459+
1460+
actor.subscribe((snapshot) => {
1461+
if (snapshot.status === 'done') {
1462+
// ...
1463+
}
1464+
});
1465+
```
1466+
1467+
</TabItem>
1468+
1469+
<TabItem value="v4" label="XState v4">
1470+
1471+
```ts
1472+
// ❌ DEPRECATED
1473+
const actor = interpret(machine);
1474+
actor.start();
1475+
1476+
actor.subscribe((state) => {
1477+
if (state.done) {
1478+
// ...
1479+
}
1480+
});
1481+
```
1482+
1483+
</TabItem>
1484+
</Tabs>
1485+
14421486
## TypeScript
14431487
14441488
### Use `types` instead of `schema`

0 commit comments

Comments
 (0)