File tree Expand file tree Collapse file tree 2 files changed +15
-4
lines changed Expand file tree Collapse file tree 2 files changed +15
-4
lines changed Original file line number Diff line number Diff 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+
6475export 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.
Original file line number Diff line number Diff 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
3940const 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 ) {
You can’t perform that action at this time.
0 commit comments