|
2 | 2 | 'xstate': major
|
3 | 3 | ---
|
4 | 4 |
|
5 |
| -**Breaking:** Activities are no longer a separate concept. Instead, activities are invoked. Internally, this is how activities worked. The API is consolidated so that `activities` are no longer a property of the state node or machine options: |
6 |
| - |
7 |
| -```diff |
8 |
| -import { createMachine } from 'xstate'; |
9 |
| -+import { invokeActivity } from 'xstate/invoke'; |
10 |
| - |
11 |
| -const machine = createMachine( |
12 |
| - { |
13 |
| - // ... |
14 |
| -- activities: 'someActivity', |
15 |
| -+ invoke: { |
16 |
| -+ src: 'someActivity' |
17 |
| -+ } |
18 |
| - }, |
19 |
| - { |
20 |
| -- activities: { |
21 |
| -+ actors: { |
22 |
| -- someActivity: ((context, event) => { |
23 |
| -+ someActivity: invokeActivity((context, event) => { |
24 |
| - // ... some continuous activity |
25 |
| - |
26 |
| - return () => { |
27 |
| - // dispose activity |
28 |
| - } |
29 |
| - }) |
30 |
| - } |
31 |
| - } |
32 |
| -); |
33 |
| -``` |
34 |
| - |
35 |
| -**Breaking:** The `services` option passed as the second argument to `createMachine(config, options)` is renamed to `actors`. Each value in `actors`should be a function that takes in `context` and `event` and returns a [behavior](TODO: link) for an actor. The provided invoke creators are: |
36 |
| - |
37 |
| -- `invokeActivity` |
38 |
| -- `invokePromise` |
39 |
| -- `invokeCallback` |
40 |
| -- `invokeObservable` |
41 |
| -- `invokeMachine` |
42 |
| - |
43 |
| -```diff |
44 |
| -import { createMachine } from 'xstate'; |
45 |
| -+import { invokePromise } from 'xstate/invoke'; |
46 |
| - |
47 |
| -const machine = createMachine( |
48 |
| - { |
49 |
| - // ... |
50 |
| - invoke: { |
51 |
| - src: 'fetchFromAPI' |
52 |
| - } |
53 |
| - }, |
54 |
| - { |
55 |
| -- services: { |
56 |
| -+ actors: { |
57 |
| -- fetchFromAPI: ((context, event) => { |
58 |
| -+ fetchFromAPI: invokePromise((context, event) => { |
59 |
| - // ... (return a promise) |
60 |
| - }) |
61 |
| - } |
62 |
| - } |
63 |
| -); |
64 |
| -``` |
65 |
| - |
66 | 5 | **Breaking:** The `state.children` property is now a mapping of invoked actor IDs to their `ActorRef` instances.
|
67 | 6 |
|
68 | 7 | **Breaking:** The way that you interface with invoked/spawned actors is now through `ActorRef` instances. An `ActorRef` is an opaque reference to an `Actor`, which should be never referenced directly.
|
69 | 8 |
|
70 |
| -**Breaking:** The `src` of an `invoke` config is now either a string that references the machine's `options.actors`, or a `BehaviorCreator`, which is a function that takes in `context` and `event` and returns a `Behavior`: |
71 |
| - |
72 |
| -```diff |
73 |
| -import { createMachine } from 'xstate'; |
74 |
| -+import { invokePromise } from 'xstate/invoke'; |
75 |
| - |
76 |
| -const machine = createMachine({ |
77 |
| - // ... |
78 |
| - invoke: { |
79 |
| -- src: (context, event) => somePromise |
80 |
| -+ src: invokePromise((context, event) => somePromise) |
81 |
| - } |
82 |
| - // ... |
83 |
| -}); |
84 |
| -``` |
85 |
| - |
86 | 9 | **Breaking:** The `origin` of an `SCXML.Event` is no longer a string, but an `ActorRef` instance.
|
0 commit comments