Skip to content

Commit 5496b10

Browse files
committed
add util to cleanup render cache
1 parent d8fac77 commit 5496b10

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

internal/animate/state.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,17 @@ export const removeStaleFrames = (
6161
return keyframes.slice(staleCount - 1);
6262
};
6363

64+
export const cleanRenderCache = (
65+
keyframes: InternalKeyframe[],
66+
renderCache: RenderCache,
67+
): RenderCache => {
68+
const newCache: RenderCache = {};
69+
for (const frame of keyframes) {
70+
newCache[frame.id] = renderCache[frame.id];
71+
}
72+
return newCache;
73+
}
74+
6475
export const renderFramesAt = (input: RenderInput): RenderOutput => {
6576
const {cache, currentFrames} = input;
6677

@@ -112,8 +123,6 @@ export const renderFramesAt = (input: RenderInput): RenderOutput => {
112123
};
113124
};
114125

115-
// TODO render cache cleaner.
116-
117126
// TODO generate internal frames. Delayed frames can just copy the previous one.
118127
// TODO store current blob when interrupts happen to use as source.
119128
// TODO don't remove any frames.

public/animate.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
Keyframe,
1111
removeStaleFrames,
1212
RenderCache,
13+
cleanRenderCache,
1314
} from "../internal/animate/state";
1415

1516
// TODO copy keyframes as soon as possible to make sure they aren't modified afterwards.
@@ -37,8 +38,8 @@ interface CallbackStore {
3738
}
3839

3940
const removeExpiredFrameCallbacks = (
40-
oldStore: CallbackStore,
4141
frames: InternalKeyframe[],
42+
oldStore: CallbackStore,
4243
): CallbackStore => {
4344
const newStore: CallbackStore = {};
4445
for (const frame of frames) {
@@ -88,7 +89,8 @@ export const canvasPath = (): CanvasAnimation => {
8889
internalFrames = transitionOutput.newFrames;
8990

9091
// Remove callbacks that are no longer associated with a known frame.
91-
callbackStore = removeExpiredFrameCallbacks(callbackStore, internalFrames);
92+
callbackStore = removeExpiredFrameCallbacks(internalFrames, callbackStore);
93+
renderCache = cleanRenderCache(internalFrames, renderCache);
9294

9395
// Populate the callback using returned frame ids.
9496
for (const newFrame of internalFrames) {

0 commit comments

Comments
 (0)