Skip to content

Commit

Permalink
ActionTypes.ts rename options.useCustom to options.useDefault
Browse files Browse the repository at this point in the history
  • Loading branch information
rafde committed Jun 28, 2024
1 parent 0e8d359 commit 5ea1a69
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion __tests__/useCTA.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1857,7 +1857,7 @@ describe( 'useCTA', function() {
{
hi: state.current.hi * 3,
},
{ useCustom: false, },
{ useDefault: true, },
);
},
},
Expand Down
4 changes: 2 additions & 2 deletions src/internal/ActionTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ type PredefinedActions = 'replace' | 'replaceInitial' | 'reset' | 'update';
export type ActionTypeConstructParam<Initial extends CTAInitial,> = {
type: PredefinedActions
nextState: Initial | Partial<Initial>
options?: { useCustom: boolean }
options?: { useDefault: boolean }
};

export class ActionType<Initial extends CTAInitial,> {
Expand All @@ -17,7 +17,7 @@ export class ActionType<Initial extends CTAInitial,> {
this.type = param.type;
this.nextState = param.nextState;
this.options = {
useCustom: true,
useDefault: false,
...param?.options,
};
}
Expand Down
12 changes: 6 additions & 6 deletions src/internal/ctaReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,23 +212,23 @@ function getActionType<
return {
next: nextState,
type,
useCustom: Boolean( options?.useCustom, ),
useDefault: Boolean( options?.useDefault, ),
} as typeof type extends 'update' ? {
next: Partial<Initial>
type: 'update'
useCustom: boolean
useDefault: boolean
} : {
next: Initial
type: Exclude<PredefinedActions, 'update'>
useCustom: boolean
useDefault: boolean
};
}

if ( ctaReturnType && typeof ctaReturnType === 'object' ) {
return {
next: ctaReturnType as Partial<Initial>,
type: 'update' as Extract<PredefinedActions, 'update'>,
useCustom: true,
useDefault: false,
};
}
}
Expand Down Expand Up @@ -346,7 +346,7 @@ export default function ctaReducer<

const {
type,
useCustom,
useDefault,
} = actionType;

let {
Expand All @@ -355,7 +355,7 @@ export default function ctaReducer<

const customPredefinedCTA = isActionsObject && actions?.[ type as keyof typeof actions ];

if ( typeof customPredefinedCTA === 'function' && useCustom ) {
if ( typeof customPredefinedCTA === 'function' && !useDefault ) {
next = customPredefinedCTA( ctaHandleState, next, );
}

Expand Down

0 comments on commit 5ea1a69

Please sign in to comment.