Skip to content

Commit

Permalink
feat: Add action name & payload to middleware args (#82)
Browse files Browse the repository at this point in the history
* feat: Add action name & payload to middleware args

Relates to #81

* feat: Change order of middleware arguments
  • Loading branch information
ciganandrea authored Feb 25, 2021
1 parent df1f780 commit aff582d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/stateMachine.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function actionTemplate<TCallback extends AnyCallback>(
if (storeFactory.middleWares.length) {
storeFactory.state = storeFactory.middleWares.reduce(
(currentValue, currentFunction) =>
currentFunction(currentValue) || currentValue,
currentFunction(currentValue, callback.name, payload) || currentValue,
storeFactory.state,
);
}
Expand Down
6 changes: 5 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ export type StateMachineContextValue = {
setState: React.Dispatch<React.SetStateAction<GlobalState>>
};

export type MiddleWare = <T>(arg: T) => T;
export type MiddleWare = (
state: GlobalState,
payload: any,
callbackName: string,
) => GlobalState;

export type StateMachineOptions = {
name: string;
Expand Down

0 comments on commit aff582d

Please sign in to comment.