-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: state value added to transition type #4043
Changes from 1 commit
6a0f1b1
3d3a385
4fac6cf
83ffd0c
d182ddc
55cbfd7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@xstate/fsm': patch | ||
--- | ||
|
||
state value added to transition type | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,10 +86,14 @@ export namespace StateMachine { | |
assignment: Assigner<TContext, TEvent> | PropertyAssigner<TContext, TEvent>; | ||
} | ||
|
||
export type Transition<TContext extends object, TEvent extends EventObject> = | ||
| string | ||
export type Transition< | ||
TContext extends object, | ||
TEvent extends EventObject, | ||
TStateValue extends string | ||
Andarist marked this conversation as resolved.
Show resolved
Hide resolved
|
||
> = | ||
| TStateValue | ||
| { | ||
target?: string; | ||
target?: TStateValue; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What exactly does this solve for you? Could you share some code that is affected by this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Andarist 2023-05-27.13-10-34.mp4
|
||
actions?: SingleOrArray<Action<TContext, TEvent>>; | ||
cond?: (context: TContext, event: TEvent) => boolean; | ||
}; | ||
|
@@ -121,13 +125,17 @@ export namespace StateMachine { | |
TState extends Typestate<TContext> = { value: any; context: TContext } | ||
> { | ||
id?: string; | ||
initial: string; | ||
initial: TState['value']; | ||
context?: TContext; | ||
states: { | ||
[key in TState['value']]: { | ||
on?: { | ||
[K in TEvent['type']]?: SingleOrArray< | ||
Transition<TContext, TEvent extends { type: K } ? TEvent : never> | ||
Transition< | ||
TContext, | ||
TEvent extends { type: K } ? TEvent : never, | ||
TState['value'] | ||
> | ||
>; | ||
}; | ||
exit?: SingleOrArray<Action<TContext, TEvent>>; | ||
|
@@ -157,9 +165,7 @@ export namespace StateMachine { | |
TState extends Typestate<TContext> = { value: any; context: TContext } | ||
> { | ||
send: (event: TEvent | TEvent['type']) => void; | ||
subscribe: ( | ||
listener: StateListener<State<TContext, TEvent, TState>> | ||
) => { | ||
subscribe: (listener: StateListener<State<TContext, TEvent, TState>>) => { | ||
unsubscribe: () => void; | ||
}; | ||
start: ( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @ksv90! Thanks for making your first contribution to @statelyai ❤️
Changesets generate changelog entries for users so you want to think like a user when writing your changesets.
If you're a user reading a changelog entry, you'd want to know things like:
Your changeset isn't technically wrong, it just doesn't help users understand or get excited about the change that you made here!