Skip to content

Commit

Permalink
export type CTAPayloadCallbackParameter
Browse files Browse the repository at this point in the history
  • Loading branch information
rafde committed Jun 27, 2024
1 parent 68163de commit 0e8d359
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ export type { UseCTAReturnType, } from './types/UseCTAReturnType';

export type { UseCTAReturnTypeDispatch, } from './types/UseCTAReturnTypeDispatch';

export type { CTAPayloadCallbackParameter, } from './types/UseCTAReturnTypeDispatch';

export type { CustomCTAStateParam, } from './types/CustomCTAStateParam';

export type { CTAStateParam, } from './types/CTAStateParam';
Expand Down
33 changes: 20 additions & 13 deletions src/types/UseCTAReturnTypeDispatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,25 @@ type OmitEmptyRecord<T,> = {
[K in keyof T as T[K] extends Record<string | number | symbol, never> ? never : K]: T[K]
};

export type CTAPayloadCallbackParameter<Initial extends CTAInitial,> = Readonly<
Pick<
CustomCTAStateParam<Initial>,
'changes' | 'current' | 'initial' | 'previous'
>
>;

type ReplaceCTAProps<Initial extends CTAInitial,> = {
type: 'replace'
payload: Initial | (
( ctaState: UseCTAReturnTypeDispatchState<Initial> ) => Initial | undefined
( ctaPayloadCallbackParameter: CTAPayloadCallbackParameter<Initial> ) => Initial | undefined
)
options?: OptionsParams
};

type ReplaceInitialCTAProps<Initial extends CTAInitial,> = {
type: 'replaceInitial'
payload: Initial | (
( ctaState: UseCTAReturnTypeDispatchState<Initial> ) => Initial | undefined
( ctaPayloadCallbackParameter: CTAPayloadCallbackParameter<Initial> ) => Initial | undefined
)
options?: OptionsParams
};
Expand All @@ -33,15 +40,15 @@ type ResetCTAProps<Initial extends CTAInitial,> = {
} | {
type: 'reset'
payload?: Initial | (
( ctaState: UseCTAReturnTypeDispatchState<Initial> ) => Initial | undefined
( ctaPayloadCallbackParameter: CTAPayloadCallbackParameter<Initial> ) => Initial | undefined
)
options?: OptionsParams
};

type UpdateCTAProps<Initial extends CTAInitial,> = {
type: 'update'
payload: Partial<Initial> | (
( ctaState: UseCTAReturnTypeDispatchState<Initial> ) => Partial<Initial> | undefined
( ctaPayloadCallbackParameter: CTAPayloadCallbackParameter<Initial> ) => Partial<Initial> | undefined
)
options?: OptionsParams
};
Expand Down Expand Up @@ -137,7 +144,7 @@ export type CustomCTAWithOptionalPayloadProps<
> = CustomCTAWithOptionalPayloadRecord<Initial, Actions> extends Record<string | number | symbol, never> ? never : {
type: keyof CustomActionsWithOptionalPayloadRecord
payload?: CustomActionsWithOptionalPayloadParameter | (
( ctaState: UseCTAReturnTypeDispatchState<Initial> ) => CustomActionsWithOptionalPayloadParameter | undefined
( ctaPayloadCallbackParameter: CTAPayloadCallbackParameter<Initial> ) => CustomActionsWithOptionalPayloadParameter | undefined
)
options?: OptionsParams
};
Expand Down Expand Up @@ -175,7 +182,7 @@ export type CustomCTAWithPayloadProps<
> = CustomActionsWithPayload extends Record<string | number | symbol, never> ? never : {
type: keyof CustomActionsWithPayload
payload: CustomActionsWithPayloadParameter | (
( ctaState: UseCTAReturnTypeDispatchState<Initial> ) => CustomActionsWithPayloadParameter | undefined
( ctaPayloadCallbackParameter: CTAPayloadCallbackParameter<Initial> ) => CustomActionsWithPayloadParameter | undefined
)
options?: OptionsParams
};
Expand Down Expand Up @@ -225,7 +232,7 @@ export type DispatchCustomCTAWithOptionalPayload<
CustomActionsWithOptionalPayloadRecord : Readonly<{
[Action in keyof CustomActionsWithOptionalPayloadRecord]: (
payload?: CustomActionsWithOptionalPayloadParameters | (
( ctaState: UseCTAReturnTypeDispatchState<Initial> ) => CustomActionsWithOptionalPayloadParameters | void
( ctaPayloadCallbackParameter: CTAPayloadCallbackParameter<Initial> ) => CustomActionsWithOptionalPayloadParameters | void
),
options?: OptionsParams,
) => void;
Expand All @@ -243,7 +250,7 @@ export type DispatchCustomCTAWithPayload<
CustomActionsWithPayloadRecord : {
[Action in keyof CustomActionsWithPayloadRecord]: (
payload: CustomActionsWithPayloadParameters | (
( ctaState: UseCTAReturnTypeDispatchState<Initial> ) => CustomActionsWithPayloadParameters | void
( ctaPayloadCallbackParameter: CTAPayloadCallbackParameter<Initial> ) => CustomActionsWithPayloadParameters | void
),
options?: OptionsParams,
) => void;
Expand All @@ -252,13 +259,13 @@ export type DispatchCustomCTAWithPayload<
export type DispatchDefaultCTARecord<Initial extends CTAInitial,> = Readonly<{
replace(
payload: Initial | (
( ctaState: UseCTAReturnTypeDispatchState<Initial> ) => Initial | undefined
( ctaPayloadCallbackParameter: CTAPayloadCallbackParameter<Initial> ) => Initial | undefined
),
options?: OptionsParams,
): void
replaceInitial(
payload: Initial | (
( ctaState: UseCTAReturnTypeDispatchState<Initial> ) => Initial | undefined
( ctaPayloadCallbackParameter: CTAPayloadCallbackParameter<Initial> ) => Initial | undefined
),
options?: OptionsParams,
): void
Expand All @@ -268,13 +275,13 @@ export type DispatchDefaultCTARecord<Initial extends CTAInitial,> = Readonly<{
): void
reset(
payload?: Initial | (
( ctaState: UseCTAReturnTypeDispatchState<Initial> ) => Initial | undefined
),
( ctaPayloadCallbackParameter: CTAPayloadCallbackParameter<Initial> ) => Initial | undefined
),
options?: OptionsParams,
): void
update(
payload: Partial<Initial> | (
( ctaState: UseCTAReturnTypeDispatchState<Initial> ) => Partial<Initial> | undefined
( ctaPayloadCallbackParameter: CTAPayloadCallbackParameter<Initial> ) => Partial<Initial> | undefined
),
options?: OptionsParams,
): void
Expand Down

0 comments on commit 0e8d359

Please sign in to comment.