Actor-based state management & orchestration for complex app logic.
MIT License
Bot releases are visible (Hide)
Published by github-actions[bot] over 1 year ago
Published by github-actions[bot] over 1 year ago
Published by github-actions[bot] over 1 year ago
#3990 fe6db147a
Thanks @davidkpiano! - You can now add a systemId
to spawned actors to reference them anywhere in the system.
const machine = createMachine({
// ...
context: ({ spawn }) => ({
actorRef: spawn(
createMachine({
// ...
}),
{ systemId: 'actorRef' }
)
})
});
#3991 98db493e4
Thanks @davidkpiano! - The actor.onDone(...)
method is removed. Use actor.subscribe({ complete() {... } })
instead.
- actor.onDone(() => { ... })
+ actor.subscribe({
+ complete() {
+ // ...
+ }
+})
Published by github-actions[bot] over 1 year ago
#4020 7898731b5
Thanks @davidkpiano! - The fromEventObservable
actor logic creator now accepts input
:
const machine = createMachine({
invoke: {
src: fromEventObservable(({ input }) => /* ... */),
input: {
foo: 'bar'
}
}
});
Published by github-actions[bot] over 1 year ago
#3947 5fa3a0c74
Thanks @davidkpiano! - Removed the ability to pass a factory function as argument to useMachine
and useInterpret
.
#4006 42df9a536
Thanks @davidkpiano! - useActorRef
is introduced, which returns an ActorRef
from actor logic:
const actorRef = useActorRef(machine, { ... });
const anotherActorRef = useActorRef(fromPromise(...));
is deprecated in favor of useMachine
useActor
, which works with machines and any other kind of logic
-const [state, send] = useMachine(machine);
+const [state, send] = useActor(machine);
const [state, send] = useActor(fromTransition(...));
is removed in favor of useSpawn
useActorRef
-const actorRef = useSpawn(machine);
+const actorRef = useActorRef(machine);
The previous use of `useActor(actorRef)` is now replaced with just using the `actorRef` directly, and with `useSelector`:
```diff
-const [state, send] = useActor(actorRef);
+const state = useSelector(actorRef, s => s);
// actorRef.send(...)
#4006 42df9a536
Thanks @davidkpiano! - useActor
has been removed from the created actor context, you should be able to replace its usage with MyCtx.useSelector
and MyCtx.useActorRef
.
#3947 5fa3a0c74
Thanks @davidkpiano! - Implementations for machines on useMachine
and useInterpret
hooks should go directly on the machine via machine.provide(...)
, and are no longer allowed to be passed in as options.
-const [state, send] = useMachine(machine, {
- actions: {
- // ...
- }
-});
+const [state, send] = useMachine(machine.provide({
+ actions: {
+ // ...
+ }
+}));
@xstate/react
will detect that the machine's config is still the same, and will not produce the "machine has changed" warning.
Published by github-actions[bot] over 1 year ago
Published by github-actions[bot] over 1 year ago
Published by github-actions[bot] over 1 year ago
fc076d82f
Thanks @davidkpiano! - Fixed an internal import to not import from xstate/src
Published by github-actions[bot] over 1 year ago
Published by github-actions[bot] over 1 year ago
Published by github-actions[bot] over 1 year ago
#898 26986f417
Thanks @davidkpiano! - Sending a string event to actor.send('some string')
will now throw a proper error message.
#3957 423c5ab72
Thanks @davidkpiano! - The machine .schema
property is now .types
:
const machine = createMachine({
// schema: { ... }
types: {} as {
context: { ... };
events: { ... };
// ...
}
});
And the .tsTypes
property is now .types.typegen
:
const machine = createMachine({
// tsTypes: { ... }
types: {} as {
typegen: {};
context: { ... };
events: { ... };
// ...
}
});
#3968 eecb31b8f
Thanks @davidkpiano! - The createEmptyActor()
function has been added to make it easier to create actors that do nothing ("empty" actors). This is useful for testing, or for some integrations such as useActor(actor)
in @xstate/react
that require an actor:
import { createEmptyActor } from 'xstate';
const SomeComponent = (props) => {
// props.actor may be undefined
const [state, send] = useActor(props.actor ?? createEmptyActor());
// ...
};
#3966 61db63bf4
Thanks @davidkpiano! - You can now import the following from xstate
:
import {
// actions
// sendTo (removed)
pure,
// interpret helpers
waitFor,
// actor functions
fromPromise,
fromObservable,
fromCallback,
fromEventObservable,
fromTransition,
// guard functions
stateIn,
not,
and,
or
}
The send
action was removed from exports; use sendTo(...)
or raise(...)
instead.
ead287257
Thanks @davidkpiano! - Unresolved promises will now be properly persisted. The current behavior is to restart a promise that is unresolved.Published by github-actions[bot] over 1 year ago
Published by github-actions[bot] over 1 year ago
Published by github-actions[bot] over 1 year ago
Published by github-actions[bot] over 1 year ago
Published by github-actions[bot] over 1 year ago
#3952 ec300837e
Thanks @davidkpiano! - The output data on final states is now specified as .output
instead of .data
:
const machine = createMachine({
// ...
states: {
// ...
success: {
- data: { message: 'Success!' }
+ output: { message: 'Success!' }
}
}
})
#2881 2f45343c5
Thanks @davidkpiano! - Target resolution improvements: targeting sibling nodes from the root is no longer valid, since the root node has no siblings:
createMachine({
id: 'direction',
initial: 'left',
states: {
left: {},
right: {}
},
on: {
- LEFT_CLICK: 'left',
+ LEFT_CLICK: '.left'
}
});
Published by github-actions[bot] over 1 year ago
#3926 f9f692b2b
Thanks @davidkpiano! - Restored state will no longer contain actions, since they are assumed to have already been executed. Actions will not be replayed.
If you want to replay actions when restoring state, it is recommended to use an event sourcing approach.
Published by github-actions[bot] over 1 year ago
Published by github-actions[bot] over 1 year ago
Published by github-actions[bot] over 1 year ago