Skip to content

Commit

Permalink
refactor: ♻️ Migrate to dequal
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Mar 10, 2022
1 parent d134a26 commit 5c524a0
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { HeadersInputs, QueryParamsInputs } from './KeyValueInputs'
import { VariableForTestInputs } from './VariableForTestInputs'
import { DataVariableInputs } from './ResponseMappingInputs'
import { byId } from 'utils'
import { deepEqual } from 'fast-equals'
import { dequal } from 'dequal'
import { SwitchWithLabel } from 'components/shared/SwitchWithLabel'

type Props = {
Expand All @@ -63,7 +63,7 @@ export const WebhookSettings = ({

useEffect(() => {
const incomingWebhook = webhooks.find(byId(webhookId))
if (deepEqual(incomingWebhook, localWebhook)) return
if (dequal(incomingWebhook, localWebhook)) return
setLocalWebhook(incomingWebhook)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [webhooks])
Expand Down
4 changes: 2 additions & 2 deletions apps/builder/components/shared/TableList.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Box, Button, Fade, Flex, IconButton, Stack } from '@chakra-ui/react'
import { TrashIcon, PlusIcon } from 'assets/icons'
import { deepEqual } from 'fast-equals'
import { dequal } from 'dequal'
import { Draft } from 'immer'
import React, { useEffect, useState } from 'react'
import { generate } from 'short-uuid'
Expand Down Expand Up @@ -35,7 +35,7 @@ export const TableList = <T,>({
const [showDeleteIndex, setShowDeleteIndex] = useState<number | null>(null)

useEffect(() => {
if (deepEqual(items, initialItems)) return
if (dequal(items, initialItems)) return
onItemsChange(items)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [items])
Expand Down
4 changes: 2 additions & 2 deletions apps/builder/contexts/TypebotContext/TypebotContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import useUndo from 'services/utils/useUndo'
import { useDebounce } from 'use-debounce'
import { itemsAction, ItemsActions } from './actions/items'
import { generate } from 'short-uuid'
import { deepEqual } from 'fast-equals'
import { dequal } from 'dequal'
import { User } from 'db'
import { saveWebhook } from 'services/webhook'
import { stringify } from 'qs'
Expand Down Expand Up @@ -179,7 +179,7 @@ export const TypebotContext = ({
...currentTypebotRef.current,
updatedAt: new Date().toISOString(),
}
if (deepEqual(omit(typebot, 'updatedAt'), omit(typebotToSave, 'updatedAt')))
if (dequal(omit(typebot, 'updatedAt'), omit(typebotToSave, 'updatedAt')))
return
setIsSavingLoading(true)
const { error } = await updateTypebot(typebotToSave.id, typebotToSave)
Expand Down
4 changes: 2 additions & 2 deletions apps/builder/contexts/UserContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
import { isDefined, isNotDefined } from 'utils'
import { updateUser as updateUserInDb } from 'services/user/user'
import { useToast } from '@chakra-ui/react'
import { deepEqual } from 'fast-equals'
import { dequal } from 'dequal'
import { User } from 'db'

const userContext = createContext<{
Expand Down Expand Up @@ -42,7 +42,7 @@ export const UserContext = ({ children }: { children: ReactNode }) => {
)

const hasUnsavedChanges = useMemo(
() => !deepEqual(session?.user, user),
() => !dequal(session?.user, user),
[session?.user, user]
)

Expand Down
2 changes: 1 addition & 1 deletion apps/builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"cuid": "^2.1.8",
"db": "*",
"deep-object-diff": "^1.1.7",
"fast-equals": "^3.0.0",
"dequal": "^2.0.2",
"focus-visible": "^5.2.0",
"framer-motion": "^4",
"google-auth-library": "^7.12.0",
Expand Down
12 changes: 6 additions & 6 deletions apps/builder/services/typebots/typebots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import {
stepTypeHasOption,
stepTypeHasWebhook,
} from 'utils'
import { deepEqual } from 'fast-equals'
import { dequal } from 'dequal'
import { stringify } from 'qs'
import { isChoiceInput, isConditionStep, sendRequest, omit } from 'utils'
import cuid from 'cuid'
Expand Down Expand Up @@ -247,7 +247,7 @@ const parseDefaultStepOptions = (type: StepWithOptionsType): StepOptions => {
}

export const checkIfTypebotsAreEqual = (typebotA: Typebot, typebotB: Typebot) =>
deepEqual(
dequal(
JSON.parse(JSON.stringify(typebotA)),
JSON.parse(JSON.stringify(typebotB))
)
Expand All @@ -265,19 +265,19 @@ export const checkIfPublished = (
)
)
return (
deepEqual(
dequal(
JSON.parse(JSON.stringify(typebot.blocks)),
JSON.parse(JSON.stringify(publicTypebot.blocks))
) &&
deepEqual(
dequal(
JSON.parse(JSON.stringify(typebot.settings)),
JSON.parse(JSON.stringify(publicTypebot.settings))
) &&
deepEqual(
dequal(
JSON.parse(JSON.stringify(typebot.theme)),
JSON.parse(JSON.stringify(publicTypebot.theme))
) &&
deepEqual(
dequal(
JSON.parse(JSON.stringify(typebot.variables)),
JSON.parse(JSON.stringify(publicTypebot.variables))
)
Expand Down
4 changes: 2 additions & 2 deletions apps/builder/services/utils/useUndo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isDefined } from '@udecode/plate-core'
import { deepEqual } from 'fast-equals'
import { dequal } from 'dequal'
// import { diff } from 'deep-object-diff'
import { useReducer, useCallback, useRef } from 'react'
import { isNotDefined } from 'utils'
Expand Down Expand Up @@ -76,7 +76,7 @@ const reducer = <T>(state: State<T>, action: Action<T>) => {
if (
isNotDefined(newPresent) ||
(present &&
deepEqual(
dequal(
JSON.parse(JSON.stringify(newPresent)),
JSON.parse(JSON.stringify(present))
))
Expand Down
1 change: 0 additions & 1 deletion packages/bot-engine/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"types": "dist/index.d.ts",
"dependencies": {
"db": "*",
"fast-equals": "^3.0.0",
"models": "*",
"qs": "^6.10.3",
"react-frame-component": "5.2.2-alpha.1",
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7077,6 +7077,11 @@ dequal@1.0.0:
resolved "https://registry.yarnpkg.com/dequal/-/dequal-1.0.0.tgz#41c6065e70de738541c82cdbedea5292277a017e"
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:
version "1.0.1"
resolved "https://registry.yarnpkg.com/des.js/-/des.js-1.0.1.tgz#5382142e1bdc53f85d86d53e5f4aa7deb91e0843"
Expand Down Expand Up @@ -8041,11 +8046,6 @@ fast-equals@^2.0.3:
resolved "https://registry.yarnpkg.com/fast-equals/-/fast-equals-2.0.4.tgz#3add9410585e2d7364c2deeb6a707beadb24b927"
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:
version "3.2.11"
resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-3.2.11.tgz#a1172ad95ceb8a16e20caa5c5e56480e5129c1d9"
Expand Down

2 comments on commit 5c524a0

@vercel
Copy link

@vercel vercel bot commented on 5c524a0 Mar 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

builder-v2 – ./apps/builder

builder-v2-git-main-typebot-io.vercel.app
builder-v2-typebot-io.vercel.app
app.typebot.io

Please sign in to comment.