Skip to content

Commit 835f7ad

Browse files
committed
Actors: re-organize Actor Logic Creators section
- Group actor logic creators into an Actor Logic Creators section - Link within the document for actor logic instead of to cheatsheet.mdx - Add headings for each actor logic type - Include actor logic creator function names in heading titles for easier search
1 parent cbb9387 commit 835f7ad

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

docs/actors.mdx

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,24 @@ In the actor model, actors are objects that can communicate with each other. The
3333
- Or emitting snapshots, which can be considered implicit events sent to subscribers.
3434
- Actors can create (spawn/invoke) new actors.
3535

36-
## Creating actor logic
36+
## Actor logic
3737

38-
Actor logic is the actor’s logical “model” (brain, blueprint, DNA, etc.) It describes how the actor should change behavior when receiving an event. You can create actor logic using **actor logic creators**. The types of actor logic you can create from XState are:
38+
Actor logic is the actor’s logical “model” (brain, blueprint, DNA, etc.) It describes how the actor should change behavior when receiving an event. You can create actor logic using **[actor logic creators](#actor-logic-creators)**. The types of actor logic you can create from XState are:
3939

40-
- [State machine logic (`createMachine(...)`)](cheatsheet.mdx#creating-a-state-machine)
41-
- [Promise logic (`fromPromise(...)`)](cheatsheet.mdx#creating-promise-logic)
42-
- [Transition logic (`fromTransition(...)`)](cheatsheet.mdx#creating-promise-logic)
43-
- [Observable logic (`fromObservable(...)`)](cheatsheet.mdx#creating-observable-logic)
44-
- [Event observable logic (`fromEventObservable(...)`)](migration.mdx#use-actor-logic-creators-for-invokesrc-instead-of-functions)
45-
- [Callback logic (`fromCallback(...)`)](cheatsheet.mdx#creating-callback-logic)
40+
- [State machine logic (`createMachine(...)`)](#createMachine)
41+
- [Promise logic (`fromPromise(...)`)](#fromPromise)
42+
- [Transition function logic (`fromTransition(...)`)](#fromTransition)
43+
- [Observable logic (`fromObservable(...)`)](#fromObservable)
44+
- [Event observable logic (`fromEventObservable(...)`)](#fromEventObservable)
45+
- [Callback logic (`fromCallback(...)`)](#fromCallback)
4646

4747
In XState, actor logic is defined by an object containing methods like `.transition(...)`, `.getInitialState()`, `.getSnapshot()`, and more. This object tells an interpreter how to update an actor’s internal state when it receives an event and which effects to execute (if any).
4848

4949
## Creating actors
5050

5151
You can create an actor, which is a “live” instance of some actor logic, via `createActor(actorLogic, options?)`. The `createActor(...)` function takes the following arguments:
5252

53-
- `actorLogic`: the [actor logic](actors.mdx#creating-actor-logic) to create an actor from
53+
- `actorLogic`: the [actor logic](actors.mdx#actor-logic) to create an actor from
5454
- `options` (optional): actor options
5555

5656
When you create an actor from actor logic via `createActor(actorLogic)`, you implicitly create an [actor system](system.mdx) where the created actor is the root actor. Any actors spawned from this root actor and its descendants are part of that actor system. The actor must be started by calling `actor.start()`, which will also start the actor system:
@@ -211,7 +211,9 @@ console.log(snapshot.output);
211211
// => 100
212212
```
213213

214-
## State machine actor logic
214+
## Actor Logic Creators
215+
216+
### State Machine Logic with `createMachine` {#createMachine}
215217

216218
You can describe actor logic as a [state machine](machines.mdx). Actors created from state machine actor logic can:
217219

@@ -244,7 +246,7 @@ toggleActor.send({ type: 'toggle' });
244246
// Logs 'active'
245247
```
246248

247-
## Promise actor logic
249+
### Promise Logic with `fromPromise` {#fromPromise}
248250

249251
Promise actor logic is described by an async process that resolves or rejects after some time. Actors created from promise logic (“promise actors”) can:
250252

@@ -277,9 +279,9 @@ promiseActor.start();
277279
// }
278280
```
279281

280-
## Transition function actors
282+
### Transition Function Logic with `fromTransition` {#fromTransition}
281283

282-
Transition actor logic is described by a [transition function](migration.mdx#use-actor-logic-creators-for-invokesrc-instead-of-functions), similar to a [reducer](cheatsheet.mdx#creating-transition-logic). Transition functions take the current `state` and received `event` object as arguments, and return the next state. Actors created from transition logic (“transition actors”) can:
284+
Transition actor logic is described by a [transition function](migration.mdx#use-actor-logic-creators-for-invokesrc-instead-of-functions), similar to a [reducer](fromTransition). Transition functions take the current `state` and received `event` object as arguments, and return the next state. Actors created from transition logic (“transition actors”) can:
283285

284286
- Receive events
285287
- Emit snapshots of its state
@@ -317,9 +319,9 @@ transitionActor.send({ type: 'increment' });
317319
// }
318320
```
319321

320-
## Observable actors
322+
### Observable Logic with `fromObservable` {#fromObservable}
321323

322-
Observable actor logic is described by an [observable stream of values](cheatsheet.mdx#creating-observable-logic). Actors created from observable logic (“observable actors”) can:
324+
Observable actor logic is described by an [observable stream of values](#fromObservable). Actors created from observable logic (“observable actors”) can:
323325

324326
- Emit snapshots of its emitted value
325327

@@ -342,7 +344,7 @@ secondActor.start();
342344
// ...
343345
```
344346

345-
## Event observable actors
347+
### Event Observable Logic with `fromEventObservable` {#fromEventObservable}
346348

347349
Event observable actor logic is described by an observable stream of [event objects](transitions.mdx#event-objects). Actors created from event observable logic (“event observable actors”) can:
348350

@@ -367,7 +369,7 @@ const canvasActor = createActor(canvasMachine);
367369
canvasActor.start();
368370
```
369371

370-
## Callback actors
372+
### Callback Logic with `fromCallback` {#fromCallback}
371373

372374
Callback actor logic is described by a callback function that receives a single object argument that includes a `sendBack(event)` function and a `receive(event => ...)` function. Actors created from callback logic (“callback actors”) can:
373375

@@ -408,7 +410,7 @@ Callback actors are a bit different from other actors in that they do not do the
408410
- Do not emit values when used with `.subscribe()`
409411
- Can not be stopped with `.stop()`
410412

411-
## Higher-level actor logic
413+
## Higher-Level Logic
412414

413415
Higher-level actor logic enhances existing actor logic with additional functionality. For example, you can create actor logic that logs or persists actor state:
414416

0 commit comments

Comments
 (0)