Skip to content

Commit

Permalink
remove isNil util
Browse files Browse the repository at this point in the history
  • Loading branch information
fkhadra committed Nov 1, 2022
1 parent 54e397a commit 3afe7ef
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/components/Toast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import cx from 'clsx';
import { ProgressBar } from './ProgressBar';
import { CloseButton } from './CloseButton';
import { ToastProps } from '../types';
import { Default, isFn, isNil } from '../utils';
import { Default, isFn } from '../utils';
import { useToast } from '../hooks/useToast';

export const Toast: React.FC<ToastProps> = props => {
Expand Down Expand Up @@ -97,7 +97,7 @@ export const Toast: React.FC<ToastProps> = props => {
}
style={bodyStyle}
>
{!isNil(iconOut) && (
{iconOut != null && (
<div
className={cx(`${Default.CSS_NAMESPACE}__toast-icon`, {
[`${Default.CSS_NAMESPACE}--animate-icon ${Default.CSS_NAMESPACE}__zoom-enter`]:
Expand Down
6 changes: 3 additions & 3 deletions src/core/toast.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { POSITION, TYPE, isStr, isNum, isFn, Type, isNil } from '../utils';
import { POSITION, TYPE, isStr, isNum, isFn, Type } from '../utils';
import { eventManager, OnChangeCallback, Event } from './eventManager';
import {
ToastContent,
Expand Down Expand Up @@ -146,7 +146,7 @@ function handlePromise<TData = unknown, TError = unknown, TPending = unknown>(
) => {
// Remove the toast if the input has not been provided. This prevents the toast from hanging
// in the pending state if a success/error toast has not been provided.
if (isNil(input)) {
if (input == null) {
toast.dismiss(id);
return;
}
Expand Down Expand Up @@ -208,7 +208,7 @@ toast.dismiss = (id?: Id) => {
if (containers.size > 0) {
eventManager.emit(Event.Clear, id);
} else {
queue = queue.filter(t => !isNil(id) && t.options.toastId !== id);
queue = queue.filter(t => id != null && t.options.toastId !== id);
}
};

Expand Down
20 changes: 10 additions & 10 deletions src/hooks/useToastContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ import {
isNum,
isStr,
getAutoCloseDelay,
toToastItem,
isNil
toToastItem
} from '../utils';
import { eventManager, Event } from '../core/eventManager';

Expand Down Expand Up @@ -97,7 +96,7 @@ export function useToastContainer(props: ToastContainerProps) {

function removeToast(toastId?: Id) {
setToastIds(state =>
isNil(toastId) ? [] : state.filter(id => id !== toastId)
toastId == null ? [] : state.filter(id => id !== toastId)
);
}

Expand All @@ -117,7 +116,7 @@ export function useToastContainer(props: ToastContainerProps) {
!containerRef.current ||
(instance.props.enableMultiContainer &&
options.containerId !== instance.props.containerId) ||
(toastToRender.has(options.toastId) && isNil(options.updateId))
(toastToRender.has(options.toastId) && options.updateId == null)
);
}

Expand All @@ -131,7 +130,7 @@ export function useToastContainer(props: ToastContainerProps) {
const { toastId, updateId, data } = options;
const { props } = instance;
const closeToast = () => removeToast(toastId);
const isNotAnUpdate = isNil(updateId);
const isNotAnUpdate = updateId == null;

if (isNotAnUpdate) instance.count++;

Expand Down Expand Up @@ -161,14 +160,15 @@ export function useToastContainer(props: ToastContainerProps) {
eventManager.emit(Event.Change, removed);

const queueLen = instance.queue.length;
instance.count = isNil(toastId)
? instance.count - instance.displayedToast
: instance.count - 1;
instance.count =
toastId == null
? instance.count - instance.displayedToast
: instance.count - 1;

if (instance.count < 0) instance.count = 0;

if (queueLen > 0) {
const freeSlot = isNil(toastId) ? instance.props.limit! : 1;
const freeSlot = toastId == null ? instance.props.limit! : 1;

if (queueLen === 1 || freeSlot === 1) {
instance.displayedToast++;
Expand Down Expand Up @@ -247,7 +247,7 @@ export function useToastContainer(props: ToastContainerProps) {
setToastIds(state => [...state, toastId].filter(id => id !== staleId));
eventManager.emit(
Event.Change,
toToastItem(toast, isNil(toast.props.updateId) ? 'added' : 'updated')
toToastItem(toast, toast.props.updateId == null ? 'added' : 'updated')
);
}

Expand Down
2 changes: 0 additions & 2 deletions src/utils/propValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ export const isFn = (v: any): v is Function => typeof v === 'function';

export const parseClassName = (v: any) => (isStr(v) || isFn(v) ? v : null);

export const isNil = (v: any) => v == null;

export const getAutoCloseDelay = (
toastAutoClose?: false | number,
containerAutoClose?: false | number
Expand Down

0 comments on commit 3afe7ef

Please sign in to comment.