[Snyk] Upgrade xstate from 5.14.0 to 5.15.0 #1730
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Snyk has created this PR to upgrade xstate from 5.14.0 to 5.15.0.
ℹ️ Keep your dependencies up-to-date. This makes it easier to fix existing vulnerabilities and to more quickly identify and fix newly disclosed vulnerabilities when they affect your project.
The recommended version is 1 version ahead of your current version.
The recommended version was released on 21 days ago.
Release notes
Package name: xstate
Minor Changes
#4976
452bce71e
Thanks @ with-heart! - Added exports for actor logic-specificActorRef
types:CallbackActorRef
,ObservableActorRef
,PromiseActorRef
, andTransitionActorRef
.Each type represents
ActorRef
narrowed to the corresponding type of logic (the type ofself
within the actor's logic):CallbackActorRef
: actor created byfromCallback
/** The events the actor receives. /
type Event = { type: 'someEvent' };
/* The actor's input. */
type Input = { name: string };
/** Actor logic that logs whenever it receives an event of type
someEvent
. */const logic = fromCallback<Event, Input>(({ self, input, receive }) => {
self;
// ^? CallbackActorRef<Event, Input>
receive((event) => {
if (event.type === 'someEvent') {
console.log(
<span class="pl-s1"><span class="pl-kos">${</span><span class="pl-s1">input</span><span class="pl-kos">.</span><span class="pl-c1">name</span><span class="pl-kos">}</span></span>: received "someEvent" event
);// logs 'myActor: received "someEvent" event'
}
});
});
const actor = createActor(logic, { input: { name: 'myActor' } });
// ^? CallbackActorRef<Event, Input>
ObservableActorRef
: actor created byfromObservable
andfromEventObservable
import { interval } from 'rxjs';
/** The type of the value observed by the actor's logic. /
type Context = number;
/* The actor's input. */
type Input = { period?: number };
/**
* Actor logic that observes a number incremented every
input.period
* milliseconds (default: 1_000).
*/
const logic = fromObservable<Context, Input>(({ input, self }) => {
self;
// ^? ObservableActorRef<Event, Input>
return interval(input.period ?? 1_000);
});
const actor = createActor(logic, { input: { period: 2_000 } });
// ^? ObservableActorRef<Event, Input>
PromiseActorRef
: actor created byfromPromise
/** The actor's resolved output. /
type Output = string;
/* The actor's input. */
type Input = { message: string };
/** Actor logic that fetches the url of an image of a cat saying
input.message
. */const logic = fromPromise<Output, Input>(async ({ input, self }) => {
self;
// ^? PromiseActorRef<Output, Input>
const data = await fetch(
https://cataas.com/cat/says/<span class="pl-s1"><span class="pl-kos">${</span><span class="pl-s1">input</span><span class="pl-kos">.</span><span class="pl-c1">message</span><span class="pl-kos">}</span></span>
);const url = await data.json();
return url;
});
const actor = createActor(logic, { input: { message: 'hello world' } });
// ^? PromiseActorRef<Output, Input>
TransitionActorRef
: actor created byfromTransition
/** The actor's stored context. /
type Context = {
/* The current count. /
count: number;
/* The amount to increase
count
by. /step: number;
};
/* The events the actor receives. /
type Event = { type: 'increment' };
/* The actor's input. */
type Input = { step?: number };
/**
* Actor logic that increments
count
bystep
when it receives an event of* type
increment
.*/
const logic = fromTransition<Context, Event, AnyActorSystem, Input>(
(state, event, actorScope) => {
actorScope.self;
// ^? TransitionActorRef<Context, Event>
},
({ input, self }) => {
self;
// ^? TransitionActorRef<Context, Event>
}
);
const actor = createActor(logic, { input: { step: 10 } });
// ^? TransitionActorRef<Context, Event>
#4949
8aa4c2b90
Thanks @ davidkpiano! - The TypeGen-related types have been removed from XState, simplifying the internal types without affecting normal XState usage.Minor Changes
#4936
c58b36dc3
Thanks @ davidkpiano! - Inspecting an actor system viaactor.system.inspect(ev => …)
now accepts a function or observer, and returns a subscription:const sub = actor.system.inspect((inspectionEvent) => {
console.log(inspectionEvent);
});
// Inspection events will be logged
actor.start();
actor.send({ type: 'anEvent' });
// ...
sub.unsubscribe();
// Will no longer log inspection events
actor.send({ type: 'someEvent' });
#4942
9caaa1f70
Thanks @ boneskull! -DoneActorEvent
andErrorActorEvent
now contain propertyactorId
, which refers to the ID of the actor the event refers to.#4935
2ac08b700
Thanks @ davidkpiano! - All actor logic creators now support emitting events:Promise actors
Transition actors
Observable actors
// ...
emit({
type: 'emitted',
msg: 'hello'
});
// ...
});
Callback actors
Patch Changes
417f35a11
Thanks @ boneskull! - Expose typeUnknownActorRef
for use when callinggetSnapshot()
on an unknownActorRef
.Important
Note: You are seeing this because you or someone else with access to this repository has authorized Snyk to open upgrade PRs.
For more information: