Skip to content

Commit

Permalink
feat(fsm): transition with partial context set
Browse files Browse the repository at this point in the history
Co-authored-by: S. Amir Mohammad Najafi <njfamirm@gmail.com>
  • Loading branch information
AliMD and njfamirm committed Mar 1, 2023
1 parent 6548cc7 commit 823377e
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions core/fsm/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export interface StateContext<TState extends string, TEventId extends string> {
export class FiniteStateMachine<
TState extends string = string,
TEventId extends string = string,
TContext extends Stringifyable = Stringifyable
TContext extends StringifyableRecord = StringifyableRecord
> {
state: StateContext<TState, TEventId> = {
to: this.config.initial,
Expand Down Expand Up @@ -83,7 +83,7 @@ export class FiniteStateMachine<
/**
* Machine transition.
*/
transition(event: TEventId, context?: TContext): TState | null {
transition(event: TEventId, context?: Partial<TContext>): TState | null {
const fromState = this.state.to;

let toState: TState | '$self' | undefined =
Expand All @@ -96,7 +96,10 @@ export class FiniteStateMachine<
this._logger.logMethodFull('transition', {event, context}, toState);

if (context !== undefined) {
this.context = context;
this.context = {
...this.context,
context,
};
}

if (toState == null) {
Expand Down

0 comments on commit 823377e

Please sign in to comment.