2
0

refactor: ♻️ Migrate to dequal

This commit is contained in:
Baptiste Arnaud
2022-03-10 18:17:51 +01:00
parent d134a265cd
commit 5c524a0432
9 changed files with 22 additions and 23 deletions

View File

@ -36,7 +36,7 @@ import { HeadersInputs, QueryParamsInputs } from './KeyValueInputs'
import { VariableForTestInputs } from './VariableForTestInputs' import { VariableForTestInputs } from './VariableForTestInputs'
import { DataVariableInputs } from './ResponseMappingInputs' import { DataVariableInputs } from './ResponseMappingInputs'
import { byId } from 'utils' import { byId } from 'utils'
import { deepEqual } from 'fast-equals' import { dequal } from 'dequal'
import { SwitchWithLabel } from 'components/shared/SwitchWithLabel' import { SwitchWithLabel } from 'components/shared/SwitchWithLabel'
type Props = { type Props = {
@ -63,7 +63,7 @@ export const WebhookSettings = ({
useEffect(() => { useEffect(() => {
const incomingWebhook = webhooks.find(byId(webhookId)) const incomingWebhook = webhooks.find(byId(webhookId))
if (deepEqual(incomingWebhook, localWebhook)) return if (dequal(incomingWebhook, localWebhook)) return
setLocalWebhook(incomingWebhook) setLocalWebhook(incomingWebhook)
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, [webhooks]) }, [webhooks])

View File

@ -1,6 +1,6 @@
import { Box, Button, Fade, Flex, IconButton, Stack } from '@chakra-ui/react' import { Box, Button, Fade, Flex, IconButton, Stack } from '@chakra-ui/react'
import { TrashIcon, PlusIcon } from 'assets/icons' import { TrashIcon, PlusIcon } from 'assets/icons'
import { deepEqual } from 'fast-equals' import { dequal } from 'dequal'
import { Draft } from 'immer' import { Draft } from 'immer'
import React, { useEffect, useState } from 'react' import React, { useEffect, useState } from 'react'
import { generate } from 'short-uuid' import { generate } from 'short-uuid'
@ -35,7 +35,7 @@ export const TableList = <T,>({
const [showDeleteIndex, setShowDeleteIndex] = useState<number | null>(null) const [showDeleteIndex, setShowDeleteIndex] = useState<number | null>(null)
useEffect(() => { useEffect(() => {
if (deepEqual(items, initialItems)) return if (dequal(items, initialItems)) return
onItemsChange(items) onItemsChange(items)
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, [items]) }, [items])

View File

@ -40,7 +40,7 @@ import useUndo from 'services/utils/useUndo'
import { useDebounce } from 'use-debounce' import { useDebounce } from 'use-debounce'
import { itemsAction, ItemsActions } from './actions/items' import { itemsAction, ItemsActions } from './actions/items'
import { generate } from 'short-uuid' import { generate } from 'short-uuid'
import { deepEqual } from 'fast-equals' import { dequal } from 'dequal'
import { User } from 'db' import { User } from 'db'
import { saveWebhook } from 'services/webhook' import { saveWebhook } from 'services/webhook'
import { stringify } from 'qs' import { stringify } from 'qs'
@ -179,7 +179,7 @@ export const TypebotContext = ({
...currentTypebotRef.current, ...currentTypebotRef.current,
updatedAt: new Date().toISOString(), updatedAt: new Date().toISOString(),
} }
if (deepEqual(omit(typebot, 'updatedAt'), omit(typebotToSave, 'updatedAt'))) if (dequal(omit(typebot, 'updatedAt'), omit(typebotToSave, 'updatedAt')))
return return
setIsSavingLoading(true) setIsSavingLoading(true)
const { error } = await updateTypebot(typebotToSave.id, typebotToSave) const { error } = await updateTypebot(typebotToSave.id, typebotToSave)

View File

@ -11,7 +11,7 @@ import {
import { isDefined, isNotDefined } from 'utils' import { isDefined, isNotDefined } from 'utils'
import { updateUser as updateUserInDb } from 'services/user/user' import { updateUser as updateUserInDb } from 'services/user/user'
import { useToast } from '@chakra-ui/react' import { useToast } from '@chakra-ui/react'
import { deepEqual } from 'fast-equals' import { dequal } from 'dequal'
import { User } from 'db' import { User } from 'db'
const userContext = createContext<{ const userContext = createContext<{
@ -42,7 +42,7 @@ export const UserContext = ({ children }: { children: ReactNode }) => {
) )
const hasUnsavedChanges = useMemo( const hasUnsavedChanges = useMemo(
() => !deepEqual(session?.user, user), () => !dequal(session?.user, user),
[session?.user, user] [session?.user, user]
) )

View File

@ -42,7 +42,7 @@
"cuid": "^2.1.8", "cuid": "^2.1.8",
"db": "*", "db": "*",
"deep-object-diff": "^1.1.7", "deep-object-diff": "^1.1.7",
"fast-equals": "^3.0.0", "dequal": "^2.0.2",
"focus-visible": "^5.2.0", "focus-visible": "^5.2.0",
"framer-motion": "^4", "framer-motion": "^4",
"google-auth-library": "^7.12.0", "google-auth-library": "^7.12.0",

View File

@ -45,7 +45,7 @@ import {
stepTypeHasOption, stepTypeHasOption,
stepTypeHasWebhook, stepTypeHasWebhook,
} from 'utils' } from 'utils'
import { deepEqual } from 'fast-equals' import { dequal } from 'dequal'
import { stringify } from 'qs' import { stringify } from 'qs'
import { isChoiceInput, isConditionStep, sendRequest, omit } from 'utils' import { isChoiceInput, isConditionStep, sendRequest, omit } from 'utils'
import cuid from 'cuid' import cuid from 'cuid'
@ -247,7 +247,7 @@ const parseDefaultStepOptions = (type: StepWithOptionsType): StepOptions => {
} }
export const checkIfTypebotsAreEqual = (typebotA: Typebot, typebotB: Typebot) => export const checkIfTypebotsAreEqual = (typebotA: Typebot, typebotB: Typebot) =>
deepEqual( dequal(
JSON.parse(JSON.stringify(typebotA)), JSON.parse(JSON.stringify(typebotA)),
JSON.parse(JSON.stringify(typebotB)) JSON.parse(JSON.stringify(typebotB))
) )
@ -265,19 +265,19 @@ export const checkIfPublished = (
) )
) )
return ( return (
deepEqual( dequal(
JSON.parse(JSON.stringify(typebot.blocks)), JSON.parse(JSON.stringify(typebot.blocks)),
JSON.parse(JSON.stringify(publicTypebot.blocks)) JSON.parse(JSON.stringify(publicTypebot.blocks))
) && ) &&
deepEqual( dequal(
JSON.parse(JSON.stringify(typebot.settings)), JSON.parse(JSON.stringify(typebot.settings)),
JSON.parse(JSON.stringify(publicTypebot.settings)) JSON.parse(JSON.stringify(publicTypebot.settings))
) && ) &&
deepEqual( dequal(
JSON.parse(JSON.stringify(typebot.theme)), JSON.parse(JSON.stringify(typebot.theme)),
JSON.parse(JSON.stringify(publicTypebot.theme)) JSON.parse(JSON.stringify(publicTypebot.theme))
) && ) &&
deepEqual( dequal(
JSON.parse(JSON.stringify(typebot.variables)), JSON.parse(JSON.stringify(typebot.variables)),
JSON.parse(JSON.stringify(publicTypebot.variables)) JSON.parse(JSON.stringify(publicTypebot.variables))
) )

View File

@ -1,5 +1,5 @@
import { isDefined } from '@udecode/plate-core' import { isDefined } from '@udecode/plate-core'
import { deepEqual } from 'fast-equals' import { dequal } from 'dequal'
// import { diff } from 'deep-object-diff' // import { diff } from 'deep-object-diff'
import { useReducer, useCallback, useRef } from 'react' import { useReducer, useCallback, useRef } from 'react'
import { isNotDefined } from 'utils' import { isNotDefined } from 'utils'
@ -76,7 +76,7 @@ const reducer = <T>(state: State<T>, action: Action<T>) => {
if ( if (
isNotDefined(newPresent) || isNotDefined(newPresent) ||
(present && (present &&
deepEqual( dequal(
JSON.parse(JSON.stringify(newPresent)), JSON.parse(JSON.stringify(newPresent)),
JSON.parse(JSON.stringify(present)) JSON.parse(JSON.stringify(present))
)) ))

View File

@ -7,7 +7,6 @@
"types": "dist/index.d.ts", "types": "dist/index.d.ts",
"dependencies": { "dependencies": {
"db": "*", "db": "*",
"fast-equals": "^3.0.0",
"models": "*", "models": "*",
"qs": "^6.10.3", "qs": "^6.10.3",
"react-frame-component": "5.2.2-alpha.1", "react-frame-component": "5.2.2-alpha.1",

View File

@ -7077,6 +7077,11 @@ dequal@1.0.0:
resolved "https://registry.yarnpkg.com/dequal/-/dequal-1.0.0.tgz#41c6065e70de738541c82cdbedea5292277a017e" resolved "https://registry.yarnpkg.com/dequal/-/dequal-1.0.0.tgz#41c6065e70de738541c82cdbedea5292277a017e"
integrity sha512-/Nd1EQbQbI9UbSHrMiKZjFLrXSnU328iQdZKPQf78XQI6C+gutkFUeoHpG5J08Ioa6HeRbRNFpSIclh1xyG0mw== integrity sha512-/Nd1EQbQbI9UbSHrMiKZjFLrXSnU328iQdZKPQf78XQI6C+gutkFUeoHpG5J08Ioa6HeRbRNFpSIclh1xyG0mw==
dequal@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/dequal/-/dequal-2.0.2.tgz#85ca22025e3a87e65ef75a7a437b35284a7e319d"
integrity sha512-q9K8BlJVxK7hQYqa6XISGmBZbtQQWVXSrRrWreHC94rMt1QL/Impruc+7p2CYSYuVIUr+YCt6hjrs1kkdJRTug==
des.js@^1.0.0: des.js@^1.0.0:
version "1.0.1" version "1.0.1"
resolved "https://registry.yarnpkg.com/des.js/-/des.js-1.0.1.tgz#5382142e1bdc53f85d86d53e5f4aa7deb91e0843" resolved "https://registry.yarnpkg.com/des.js/-/des.js-1.0.1.tgz#5382142e1bdc53f85d86d53e5f4aa7deb91e0843"
@ -8041,11 +8046,6 @@ fast-equals@^2.0.3:
resolved "https://registry.yarnpkg.com/fast-equals/-/fast-equals-2.0.4.tgz#3add9410585e2d7364c2deeb6a707beadb24b927" resolved "https://registry.yarnpkg.com/fast-equals/-/fast-equals-2.0.4.tgz#3add9410585e2d7364c2deeb6a707beadb24b927"
integrity sha512-caj/ZmjHljPrZtbzJ3kfH5ia/k4mTJe/qSiXAGzxZWRZgsgDV0cvNaQULqUX8t0/JVlzzEdYOwCN5DmzTxoD4w== integrity sha512-caj/ZmjHljPrZtbzJ3kfH5ia/k4mTJe/qSiXAGzxZWRZgsgDV0cvNaQULqUX8t0/JVlzzEdYOwCN5DmzTxoD4w==
fast-equals@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/fast-equals/-/fast-equals-3.0.0.tgz#efbe679d4c0d74040f61d4dda3e6bcb3bdccab82"
integrity sha512-Af7nSOpf7617idrFg0MJY6x7yVDPoO80aSwtKTC0afT8B/SsmvTpA+2a+uPLmhVF5IHmY5NPuBAA3dJrp55rJA==
fast-glob@^3.2.11, fast-glob@^3.2.7, fast-glob@^3.2.9: fast-glob@^3.2.11, fast-glob@^3.2.7, fast-glob@^3.2.9:
version "3.2.11" version "3.2.11"
resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-3.2.11.tgz#a1172ad95ceb8a16e20caa5c5e56480e5129c1d9" resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-3.2.11.tgz#a1172ad95ceb8a16e20caa5c5e56480e5129c1d9"