Skip to content

Commit

Permalink
update to new understanding of derived update propegation
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathonRP committed Jan 8, 2025
1 parent cbe947c commit 74296c4
Show file tree
Hide file tree
Showing 16 changed files with 241 additions and 228 deletions.
5 changes: 4 additions & 1 deletion src/lib/components/motion/AnimateLayout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@
<motion.div
active={1 * !active}
layout
class="handle"
transition={spring}
onLayoutUpdate={(...args) => {
console.log("change", args);
}}
class="handle"
/>
</button>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Copyright (c) 2018 Framer B.V. -->
},
};
const { nonce } = $derived(useContext(MotionConfigContext).current);
const { nonce } = $derived({ ...useContext(MotionConfigContext).current! });
/**
* We create and inject a style block so we can apply this explicit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ Copyright (c) 2018 Framer B.V. -->
children,
}: Props = $props();
const presenceChildren = newChildrenMap();
const presenceChildren = $derived(newChildrenMap());
const id = useId();
const memoOnExitComplete = $derived((childId: string | number) => {
const memoExitComplete = $derived((childId: string | number) => {
presenceChildren.set(childId, true);
for (const isComplete of presenceChildren.values()) {
if (!isComplete) return;
Expand All @@ -46,7 +46,7 @@ Copyright (c) 2018 Framer B.V. -->
initial,
isPresent,
custom,
onExitComplete: memoOnExitComplete,
onExitComplete: memoExitComplete,
register: (childId: string | number) => {
presenceChildren.set(childId, false);
return () => presenceChildren.delete(childId);
Expand All @@ -56,7 +56,7 @@ Copyright (c) 2018 Framer B.V. -->
const context = useContext(PresenceContext);
$effect(() => {
memoOnExitComplete;
memoExitComplete;
if (presenceAffectsLayout) {
context.current = presenceProps();
}
Expand All @@ -66,19 +66,21 @@ Copyright (c) 2018 Framer B.V. -->
presenceChildren.forEach((_, key) => presenceChildren.set(key, false)),
);
PresenceContext.Provider = context.current;
// $inspect(isPresent);
$effect(() => {
$effect.pre(() => {
// $inspect.trace();
memoOnExitComplete;
memoExitComplete;
context.current = presenceProps();
keyset(isPresent);
});
tick().then(() => {
!isPresent && !presenceChildren.size && onExitComplete?.();
});
$effect.pre(() => {
PresenceContext.Provider = context.current;
});
// $inspect(isPresent);
$effect(() => {
!isPresent && !presenceChildren.size && onExitComplete?.();
});
</script>

Expand Down
12 changes: 5 additions & 7 deletions src/lib/motion-start/components/LayoutGroup/LayoutGroup.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@ Copyright (c) 2018 Framer B.V. -->
let { id, inherit = true, children }: Props = $props();
const layoutGroupContext = $derived(useContext(LayoutGroupContext).current);
const layoutGroupContext = useContext(LayoutGroupContext);
const deprecatedLayoutGroupContext = $derived(
useContext(DeprecatedLayoutGroupContext).current,
);
const deprecatedLayoutGroupContext = useContext(DeprecatedLayoutGroupContext);
const [forceRender, key] = useForceUpdate();
Expand All @@ -43,7 +41,7 @@ Copyright (c) 2018 Framer B.V. -->
} as MutableRefObject<LayoutGroupContext | null>;
const upstreamId = $derived(
layoutGroupContext?.id || deprecatedLayoutGroupContext,
layoutGroupContext.current?.id || deprecatedLayoutGroupContext.current,
);
$effect(() => {
Expand All @@ -55,7 +53,7 @@ Copyright (c) 2018 Framer B.V. -->
context.current = {
id,
group: shouldInheritGroup(inherit!)
? layoutGroupContext?.group || nodeGroup()
? layoutGroupContext.current?.group || nodeGroup()
: nodeGroup(),
};
}
Expand All @@ -68,7 +66,7 @@ Copyright (c) 2018 Framer B.V. -->
};
});
$effect(() => {
$effect.pre(() => {
LayoutGroupContext.Provider = memo(key);
});
</script>
Expand Down
5 changes: 4 additions & 1 deletion src/lib/motion-start/components/Reorder/Group.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,10 @@ Copyright (c) 2018 Framer B.V. -->
if (!isReordering) return;
isReordering = false;
});
ReorderContext.Provider = context;
$effect.pre(() => {
ReorderContext.Provider = context;
});
</script>

<motion.group {...props} bind:ref ignoreStrict>
Expand Down
7 changes: 4 additions & 3 deletions src/lib/motion-start/components/Reorder/Item.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Copyright (c) 2018 Framer B.V. -->
}
>;
const context = $derived(useContext(ReorderContext).current);
const context = $derived({ ...useContext(ReorderContext).current });
const point = $derived({
x: useDefaultMotionValue(style?.x),
y: useDefaultMotionValue(style?.y),
Expand Down Expand Up @@ -107,11 +107,12 @@ Copyright (c) 2018 Framer B.V. -->
event.stopPropagation();

const { velocity } = gesturePoint;
velocity[axis] && updateOrder(value, point[axis].get(), velocity[axis]);
velocity[axis] &&
updateOrder?.(value, point[axis].get(), velocity[axis]);

onDrag && onDrag(event, gesturePoint);
}}
onLayoutMeasure={(measured: Box) => registerItem(value, measured)}
onLayoutMeasure={(measured: Box) => registerItem?.(value, measured)}
bind:ref
ignoreStrict
>
Expand Down
Loading

0 comments on commit 74296c4

Please sign in to comment.