From cbde739746645b6e766ff9ccfca5dd8e47fac147 Mon Sep 17 00:00:00 2001 From: Matt Perry Date: Fri, 8 Jul 2022 11:25:54 +0200 Subject: [PATCH] Improving code-splitting (#1613) * Improving code-splitting * Fixing import --- .../src/motion/__tests__/static-prop.test.tsx | 2 +- .../motion/features/layout/MeasureLayout.tsx | 2 +- .../projection/node/create-projection-node.ts | 20 +------------------ .../framer-motion/src/projection/node/id.ts | 2 +- .../src/projection/node/state.ts | 18 +++++++++++++++++ 5 files changed, 22 insertions(+), 22 deletions(-) create mode 100644 packages/framer-motion/src/projection/node/state.ts diff --git a/packages/framer-motion/src/motion/__tests__/static-prop.test.tsx b/packages/framer-motion/src/motion/__tests__/static-prop.test.tsx index aa42e343e1..34c739b4bd 100644 --- a/packages/framer-motion/src/motion/__tests__/static-prop.test.tsx +++ b/packages/framer-motion/src/motion/__tests__/static-prop.test.tsx @@ -3,7 +3,7 @@ import { motion, useMotionValue } from "../.." import * as React from "react" import { motionValue } from "../../value" import { MotionConfig } from "../../components/MotionConfig" -import { globalProjectionState } from "../../projection/node/create-projection-node" +import { globalProjectionState } from "../../projection/node/state" describe("isStatic prop", () => { test("it prevents rendering of animated values", async () => { diff --git a/packages/framer-motion/src/motion/features/layout/MeasureLayout.tsx b/packages/framer-motion/src/motion/features/layout/MeasureLayout.tsx index 510779f5bb..a5c56ae729 100644 --- a/packages/framer-motion/src/motion/features/layout/MeasureLayout.tsx +++ b/packages/framer-motion/src/motion/features/layout/MeasureLayout.tsx @@ -6,7 +6,7 @@ import { LayoutGroupContextProps, } from "../../../context/LayoutGroupContext" import { SwitchLayoutGroupContext } from "../../../context/SwitchLayoutGroupContext" -import { globalProjectionState } from "../../../projection/node/create-projection-node" +import { globalProjectionState } from "../../../projection/node/state" import { correctBorderRadius } from "../../../projection/styles/scale-border-radius" import { correctBoxShadow } from "../../../projection/styles/scale-box-shadow" import { addScaleCorrector } from "../../../projection/styles/scale-correction" diff --git a/packages/framer-motion/src/projection/node/create-projection-node.ts b/packages/framer-motion/src/projection/node/create-projection-node.ts index f7067ff6b9..005ae83bde 100644 --- a/packages/framer-motion/src/projection/node/create-projection-node.ts +++ b/packages/framer-motion/src/projection/node/create-projection-node.ts @@ -41,6 +41,7 @@ import { FlatTree } from "../../render/utils/flat-tree" import { Transition } from "../../types" import { resolveMotionValue } from "../../value/utils/resolve-motion-value" import { MotionStyle } from "../../motion/types" +import { globalProjectionState } from "./state" /** * We use 1000 as the animation target as 0-1000 maps better to pixels than 0-1 @@ -48,25 +49,6 @@ import { MotionStyle } from "../../motion/types" */ const animationTarget = 1000 -/** - * This should only ever be modified on the client otherwise it'll - * persist through server requests. If we need instanced states we - * could lazy-init via root. - */ -export const globalProjectionState = { - /** - * Global flag as to whether the tree has animated since the last time - * we resized the window - */ - hasAnimatedSinceResize: true, - - /** - * We set this to true once, on the first update. Any nodes added to the tree beyond that - * update will be given a `data-projection-id` attribute. - */ - hasEverUpdated: false, -} - export function createProjectionNode({ attachResizeListener, defaultParent, diff --git a/packages/framer-motion/src/projection/node/id.ts b/packages/framer-motion/src/projection/node/id.ts index 5a36dd36b2..cd0fae3230 100644 --- a/packages/framer-motion/src/projection/node/id.ts +++ b/packages/framer-motion/src/projection/node/id.ts @@ -1,5 +1,5 @@ import { useConstant } from "../../utils/use-constant" -import { globalProjectionState } from "./create-projection-node" +import { globalProjectionState } from "./state" let id = 1 export function useProjectionId(): number | undefined { diff --git a/packages/framer-motion/src/projection/node/state.ts b/packages/framer-motion/src/projection/node/state.ts new file mode 100644 index 0000000000..cdae76ad92 --- /dev/null +++ b/packages/framer-motion/src/projection/node/state.ts @@ -0,0 +1,18 @@ +/** + * This should only ever be modified on the client otherwise it'll + * persist through server requests. If we need instanced states we + * could lazy-init via root. + */ +export const globalProjectionState = { + /** + * Global flag as to whether the tree has animated since the last time + * we resized the window + */ + hasAnimatedSinceResize: true, + + /** + * We set this to true once, on the first update. Any nodes added to the tree beyond that + * update will be given a `data-projection-id` attribute. + */ + hasEverUpdated: false, +}