Renamed nullable utils into isDefined and isUndefinedOrNull (#4402)

* Renamed nullable utils into isDefined and isUndefinedOrNull
This commit is contained in:
Lucas Bordeau
2024-03-11 14:28:57 +01:00
committed by GitHub
parent 3f15cc5b7a
commit 581dfafe11
169 changed files with 469 additions and 493 deletions

View File

@ -1,7 +1,7 @@
import { ReactNode, useLayoutEffect, useRef, useState } from 'react';
import styled from '@emotion/styled';
import { isNonNullable } from '~/utils/isNonNullable';
import { isDefined } from '~/utils/isDefined';
type ComputeNodeDimensionsProps = {
children: (
@ -34,7 +34,7 @@ export const ComputeNodeDimensions = ({
return;
}
const resizeObserver = new ResizeObserver(() => {
if (isNonNullable(nodeWrapperRef.current)) {
if (isDefined(nodeWrapperRef.current)) {
setNodeDimensions({
width: nodeWrapperRef.current.offsetWidth,
height: nodeWrapperRef.current.offsetHeight,

View File

@ -2,7 +2,7 @@ import { Options, useHotkeys } from 'react-hotkeys-hook';
import { Keys } from 'react-hotkeys-hook/dist/types';
import { useRecoilState } from 'recoil';
import { isNonNullable } from '~/utils/isNonNullable';
import { isDefined } from '~/utils/isDefined';
import { pendingHotkeyState } from '../states/internal/pendingHotkeysState';
@ -58,7 +58,7 @@ export const useSequenceHotkeys = (
setPendingHotkey(null);
if (isNonNullable(options.preventDefault)) {
if (isDefined(options.preventDefault)) {
keyboardEvent.stopImmediatePropagation();
keyboardEvent.stopPropagation();
keyboardEvent.preventDefault();

View File

@ -1,6 +1,6 @@
import { useRecoilCallback } from 'recoil';
import { isNonNullable } from '~/utils/isNonNullable';
import { isDefined } from '~/utils/isDefined';
import { DEFAULT_HOTKEYS_SCOPE_CUSTOM_SCOPES } from '../constants/DefaultHotkeysScopeCustomScopes';
import { currentHotkeyScopeState } from '../states/internal/currentHotkeyScopeState';
@ -30,7 +30,7 @@ export const useSetHotkeyScope = () =>
.getValue();
if (currentHotkeyScope.scope === hotkeyScopeToSet) {
if (!isNonNullable(customScopes)) {
if (!isDefined(customScopes)) {
if (
isCustomScopesEqual(
currentHotkeyScope?.customScopes,

View File

@ -2,7 +2,7 @@ import React from 'react';
import { act } from 'react-dom/test-utils';
import { fireEvent, render, renderHook } from '@testing-library/react';
import { isNonNullable } from '~/utils/isNonNullable';
import { isDefined } from '~/utils/isDefined';
import {
ClickOutsideMode,
@ -48,7 +48,7 @@ describe('useListenClickOutside', () => {
);
act(() => {
if (isNonNullable(containerRef.current)) {
if (isDefined(containerRef.current)) {
fireEvent.mouseDown(containerRef.current);
fireEvent.click(containerRef.current);
}
@ -97,7 +97,7 @@ describe('useListenClickOutsideByClassName', () => {
act(() => {
const notClickableElement = container.querySelector('.will-trigger');
if (isNonNullable(notClickableElement)) {
if (isDefined(notClickableElement)) {
fireEvent.mouseDown(notClickableElement);
fireEvent.click(notClickableElement);
}
@ -124,7 +124,7 @@ describe('useListenClickOutsideByClassName', () => {
act(() => {
const notClickableElement = container.querySelector('.wont-trigger');
if (isNonNullable(notClickableElement)) {
if (isDefined(notClickableElement)) {
fireEvent.mouseDown(notClickableElement);
fireEvent.click(notClickableElement);
}

View File

@ -7,7 +7,7 @@ import {
ClickOutsideMode,
useListenClickOutsideV2,
} from '@/ui/utilities/pointer-event/hooks/useListenClickOutsideV2';
import { isNonNullable } from '~/utils/isNonNullable';
import { isDefined } from '~/utils/isDefined';
const containerRef = React.createRef<HTMLDivElement>();
const nullRef = React.createRef<HTMLDivElement>();
@ -77,7 +77,7 @@ describe('useListenClickOutsideV2', () => {
);
act(() => {
if (isNonNullable(containerRef.current)) {
if (isDefined(containerRef.current)) {
fireEvent.mouseDown(containerRef.current);
fireEvent.click(containerRef.current);
}
@ -101,7 +101,7 @@ describe('useListenClickOutsideV2', () => {
);
act(() => {
if (isNonNullable(containerRef.current)) {
if (isDefined(containerRef.current)) {
fireEvent.mouseDown(containerRef.current);
fireEvent.click(containerRef.current);
}

View File

@ -8,7 +8,7 @@ import {
} from '@/ui/utilities/pointer-event/hooks/useListenClickOutsideV2';
import { ClickOutsideListenerCallback } from '@/ui/utilities/pointer-event/types/ClickOutsideListenerCallback';
import { getScopeIdFromComponentId } from '@/ui/utilities/recoil-scope/utils/getScopeIdFromComponentId';
import { isNonNullable } from '~/utils/isNonNullable';
import { isDefined } from '~/utils/isDefined';
export const useClickOutsideListener = (componentId: string) => {
// TODO: improve typing
@ -67,7 +67,7 @@ export const useClickOutsideListener = (componentId: string) => {
(callback) => callback.callbackId === callbackId,
);
if (!isNonNullable(existingCallbackWithSameId)) {
if (!isDefined(existingCallbackWithSameId)) {
const existingCallbacksWithNewCallback = existingCallbacks.concat({
callbackId,
callbackFunction,

View File

@ -5,7 +5,7 @@ import { RecoilRoot, useRecoilValue } from 'recoil';
import { useListenScroll } from '@/ui/utilities/scroll/hooks/useListenScroll';
import { isScrollingState } from '@/ui/utilities/scroll/states/isScrollingState';
import { isNonNullable } from '~/utils/isNonNullable';
import { isDefined } from '~/utils/isDefined';
const containerRef = React.createRef<HTMLDivElement>();
@ -40,7 +40,7 @@ describe('useListenScroll', () => {
const container = document.querySelector('#container');
act(() => {
if (isNonNullable(container)) fireEvent.scroll(container);
if (isDefined(container)) fireEvent.scroll(container);
});
expect(result.current.isScrolling).toBe(true);

View File

@ -1,13 +1,13 @@
import { useContext } from 'react';
import { isNullable } from '~/utils/isNullable';
import { isUndefinedOrNull } from '~/utils/isUndefinedOrNull';
import { ScrollWrapperContext } from '../components/ScrollWrapper';
export const useScrollWrapperScopedRef = () => {
const scrollWrapperRef = useContext(ScrollWrapperContext);
if (isNullable(scrollWrapperRef))
if (isUndefinedOrNull(scrollWrapperRef))
throw new Error(
`Using a scroll ref without a ScrollWrapper : verify that you are using a ScrollWrapper if you intended to do so.`,
);