Skip to content

Commit

Permalink
Improving code-splitting (#1613)
Browse files Browse the repository at this point in the history
* Improving code-splitting

* Fixing import
  • Loading branch information
mattgperry committed Jul 8, 2022
1 parent b784fb6 commit cbde739
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,32 +41,14 @@ 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
* which has a noticeable difference in spring animations
*/
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<I>({
attachResizeListener,
defaultParent,
Expand Down
2 changes: 1 addition & 1 deletion packages/framer-motion/src/projection/node/id.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
18 changes: 18 additions & 0 deletions packages/framer-motion/src/projection/node/state.ts
Original file line number Diff line number Diff line change
@@ -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,
}

0 comments on commit cbde739

Please sign in to comment.