Skip to content

Commit

Permalink
remove excessive validation
Browse files Browse the repository at this point in the history
  • Loading branch information
fkhadra committed Nov 1, 2022
1 parent 4952d94 commit 54e397a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 43 deletions.
46 changes: 6 additions & 40 deletions src/hooks/useToastContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
import {
parseClassName,
canBeRendered,
isBool,
isFn,
isNum,
isStr,
Expand All @@ -28,8 +27,7 @@ import {
Toast,
ToastPosition,
ClearWaitingQueueParams,
NotValidatedToastProps,
ToastTransition
NotValidatedToastProps
} from '../types';

import { getIcon } from '../components/Icons';
Expand Down Expand Up @@ -137,57 +135,25 @@ export function useToastContainer(props: ToastContainerProps) {

if (isNotAnUpdate) instance.count++;

const toastProps: ToastProps = {
const toastProps = {
...props,
...options,
toastId,
updateId,
data,
containerId: options.containerId,
isLoading: options.isLoading,
theme: options.theme || props.theme!,
icon: options.icon ?? props.icon,
closeToast,
isIn: false,
key: options.key || instance.toastKey++,
type: options.type!,
closeToast: closeToast,
closeButton: options.closeButton,
rtl: props.rtl,
position: options.position || (props.position as ToastPosition),
transition: options.transition || (props.transition as ToastTransition),
className: parseClassName(options.className || props.toastClassName),
bodyClassName: parseClassName(
options.bodyClassName || props.bodyClassName
),
style: options.style || props.toastStyle,
bodyStyle: options.bodyStyle || props.bodyStyle,
onClick: options.onClick || props.onClick,
pauseOnHover: isBool(options.pauseOnHover)
? options.pauseOnHover
: props.pauseOnHover,
pauseOnFocusLoss: isBool(options.pauseOnFocusLoss)
? options.pauseOnFocusLoss
: props.pauseOnFocusLoss,
draggable: isBool(options.draggable)
? options.draggable
: props.draggable,
draggablePercent:
options.draggablePercent || (props.draggablePercent as number),
draggableDirection:
options.draggableDirection || props.draggableDirection,
closeOnClick: isBool(options.closeOnClick)
? options.closeOnClick
: props.closeOnClick,
progressClassName: parseClassName(
options.progressClassName || props.progressClassName
),
progressStyle: options.progressStyle || props.progressStyle,
autoClose: options.isLoading
? false
: getAutoCloseDelay(options.autoClose, props.autoClose),
hideProgressBar: isBool(options.hideProgressBar)
? options.hideProgressBar
: props.hideProgressBar,
progress: options.progress,
role: options.role || props.role,
deleteToast() {
const removed = toToastItem(toastToRender.get(toastId)!, 'removed');
toastToRender.delete(toastId);
Expand Down Expand Up @@ -217,7 +183,7 @@ export function useToastContainer(props: ToastContainerProps) {
forceUpdate();
}
}
};
} as ToastProps;

toastProps.iconOut = getIcon(toastProps);

Expand Down
2 changes: 1 addition & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ export interface ToastOptions<Data = {}> extends CommonOptions {
/**
* @deprecated
* ⚠️ Will be removed in the next major release. You can rely on `toast.onChange` instead.
*
*
* Called when toast is unmounted.
*/
onClose?: <T = {}>(props: T) => void;
Expand Down
2 changes: 0 additions & 2 deletions src/utils/propValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { isValidElement } from 'react';
export const isNum = (v: any): v is Number =>
typeof v === 'number' && !isNaN(v);

export const isBool = (v: any): v is Boolean => typeof v === 'boolean';

export const isStr = (v: any): v is String => typeof v === 'string';

export const isFn = (v: any): v is Function => typeof v === 'function';
Expand Down

0 comments on commit 54e397a

Please sign in to comment.