Skip to content

Commit

Permalink
Removing more optional chains
Browse files Browse the repository at this point in the history
  • Loading branch information
mattgperry committed Feb 14, 2023
1 parent 211446c commit 44e238a
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 24 deletions.
6 changes: 3 additions & 3 deletions packages/framer-motion/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"bundlesize": [
{
"path": "./dist/size-rollup-motion.js",
"maxSize": "29.89 kB"
"maxSize": "29.82 kB"
},
{
"path": "./dist/size-rollup-m.js",
Expand All @@ -84,7 +84,7 @@
},
{
"path": "./dist/size-rollup-dom-max.js",
"maxSize": "25.65 kB"
"maxSize": "25.56 kB"
},
{
"path": "./dist/size-webpack-m.js",
Expand All @@ -96,7 +96,7 @@
},
{
"path": "./dist/size-webpack-dom-max.js",
"maxSize": "30.5 kB"
"maxSize": "30.45 kB"
}
],
"gitHead": "ee87da357b48f83024e97e581157a5d6f620ce30"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ export class VisualElementDragControls {
? externalMotionValue
: this.visualElement.getValue(
axis,
(props.initial && props.initial[axis]) || 0
(props.initial ? props.initial[axis] : undefined) || 0
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class InViewFeature extends Feature<Element> {
const { root, margin: rootMargin, amount = "some", once } = viewport

const options = {
root: root?.current,
root: root ? root.current : undefined,
rootMargin,
threshold:
typeof amount === "number" ? amount : thresholdNames[amount],
Expand Down
14 changes: 12 additions & 2 deletions packages/framer-motion/src/projection/geometry/delta-calc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,18 @@ export function calcBoxDelta(
target: Box,
origin?: ResolvedValues
): void {
calcAxisDelta(delta.x, source.x, target.x, origin?.originX as number)
calcAxisDelta(delta.y, source.y, target.y, origin?.originY as number)
calcAxisDelta(
delta.x,
source.x,
target.x,
origin ? (origin.originX as number) : undefined
)
calcAxisDelta(
delta.y,
source.y,
target.y,
origin ? (origin.originY as number) : undefined
)
}

export function calcRelativeAxis(target: Axis, relative: Axis, parent: Axis) {
Expand Down
16 changes: 14 additions & 2 deletions packages/framer-motion/src/projection/geometry/delta-remove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,18 @@ export function removeBoxTransforms(
originBox?: Box,
sourceBox?: Box
): void {
removeAxisTransforms(box.x, transforms, xKeys, originBox?.x, sourceBox?.x)
removeAxisTransforms(box.y, transforms, yKeys, originBox?.y, sourceBox?.y)
removeAxisTransforms(
box.x,
transforms,
xKeys,
originBox ? originBox.x : undefined,
sourceBox ? sourceBox.x : undefined
)
removeAxisTransforms(
box.y,
transforms,
yKeys,
originBox ? originBox.y : undefined,
sourceBox ? sourceBox.y : undefined
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,8 @@ export function createProjectionNode<I>({

// TODO: Check here if an animation exists
const layoutTransition =
this.options.transition ??
visualElement.getDefaultTransition() ??
this.options.transition ||
visualElement.getDefaultTransition() ||
defaultLayoutTransition

const {
Expand Down Expand Up @@ -579,8 +579,9 @@ export function createProjectionNode<I>({
if (layoutId === undefined && !layout) return

const transformTemplate = this.getTransformTemplate()
this.prevTransformTemplateValue =
transformTemplate && transformTemplate(this.latestValues, "")
this.prevTransformTemplateValue = transformTemplate
? transformTemplate(this.latestValues, "")
: undefined

this.updateSnapshot()
shouldNotifyListeners && this.notifyListeners("willUpdate")
Expand Down Expand Up @@ -1212,7 +1213,10 @@ export function createProjectionNode<I>({

scheduleRender(notifyAll = true) {
this.options.scheduleRender && this.options.scheduleRender()
notifyAll && this.getStack()?.scheduleRender()
if (notifyAll) {
const stack = this.getStack()
stack && stack.scheduleRender()
}
if (this.resumingFrom && !this.resumingFrom.instance) {
this.resumingFrom = undefined
}
Expand All @@ -1232,7 +1236,9 @@ export function createProjectionNode<I>({
hasOnlyRelativeTargetChanged: boolean = false
) {
const snapshot = this.snapshot
const snapshotLatestValues = snapshot?.latestValues || {}
const snapshotLatestValues = snapshot
? snapshot.latestValues
: undefined || {}
const mixedValues = { ...this.latestValues }

const targetDelta = createDelta()
Expand Down Expand Up @@ -1268,7 +1274,8 @@ export function createProjectionNode<I>({
this.relativeTarget &&
this.relativeTargetOrigin &&
this.layout &&
this.relativeParent?.layout
this.relativeParent &&
this.relativeParent.layout
) {
calcRelativePosition(
relativeLayout,
Expand Down Expand Up @@ -1308,7 +1315,7 @@ export function createProjectionNode<I>({
startAnimation(options: AnimationOptions<number>) {
this.notifyListeners("animationStart")

this.currentAnimation?.stop()
this.currentAnimation && this.currentAnimation.stop()
if (this.resumingFrom) {
this.resumingFrom.currentAnimation?.stop()
}
Expand All @@ -1328,10 +1335,10 @@ export function createProjectionNode<I>({
...(options as any),
onUpdate: (latest: number) => {
this.mixTargetDelta(latest)
options.onUpdate?.(latest)
options.onUpdate && options.onUpdate(latest)
},
onComplete: () => {
options.onComplete?.()
options.onComplete && options.onComplete()
this.completeAnimation()
},
})
Expand All @@ -1350,7 +1357,8 @@ export function createProjectionNode<I>({
this.resumingFrom.preserveOpacity = undefined
}

this.getStack()?.exitAnimationComplete()
const stack = this.getStack()
stack && stack.exitAnimationComplete()
this.resumingFrom =
this.currentAnimation =
this.animationValues =
Expand All @@ -1361,7 +1369,7 @@ export function createProjectionNode<I>({

finishAnimation() {
if (this.currentAnimation) {
this.mixTargetDelta?.(animationTarget)
this.mixTargetDelta && this.mixTargetDelta(animationTarget)
this.currentAnimation.stop()
}

Expand Down Expand Up @@ -1533,7 +1541,7 @@ export function createProjectionNode<I>({

// Force a render of this element to apply the transform with all rotations
// set to 0.
visualElement?.render()
visualElement.render()

// Put back all the values we reset
for (const key in resetValues) {
Expand Down Expand Up @@ -1803,7 +1811,8 @@ function notifyLayoutUpdate(node: IProjectionNode) {
hasRelativeTargetChanged,
})
} else if (node.isLead()) {
node.options.onExitComplete?.()
const { onExitComplete } = node.options
onExitComplete && onExitComplete()
}

/**
Expand Down Expand Up @@ -1841,7 +1850,7 @@ function clearMeasurements(node: IProjectionNode) {

function resetTransformStyle(node: IProjectionNode) {
const { visualElement } = node.options
if (visualElement?.getProps().onBeforeLayoutMeasure) {
if (visualElement && visualElement.getProps().onBeforeLayoutMeasure) {
visualElement.notify("BeforeLayoutMeasure")
}

Expand Down

0 comments on commit 44e238a

Please sign in to comment.