Hotfix for the aggregate tracks not getting updated on changes

Co-authored-by: Fülöp <fulopkovacs@users.noreply.github.com>
This commit is contained in:
Aria Minaei 2022-05-30 16:43:01 +02:00
parent 564e54c314
commit 9d767a08ac
3 changed files with 37 additions and 10 deletions

View file

@ -42,10 +42,14 @@ function useForceUpdate(debugLabel?: string) {
* whenever there's a change in the values of the dependency array, or in the * whenever there's a change in the values of the dependency array, or in the
* derivations that are used within the callback function. * derivations that are used within the callback function.
* *
*
* @param fn - The callback function * @param fn - The callback function
* @param deps - The dependency array * @param deps - The dependency array
* @param debugLabel - The label used by the debugger * @param debugLabel - The label used by the debugger
*
* @remarks
*
* A common mistake with `usePrism()` is not including its deps in its dependency array. Let's
* have an eslint rule to catch that.
*/ */
export function usePrism<T>( export function usePrism<T>(
fn: () => T, fn: () => T,

View file

@ -164,9 +164,10 @@ function useAggregateKeyframeEditorUtils(
'index' | 'aggregateKeyframes' | 'selection' | 'viewModel' 'index' | 'aggregateKeyframes' | 'selection' | 'viewModel'
>, >,
) { ) {
return usePrism(() => { const {index, aggregateKeyframes, selection} = props
const {index, aggregateKeyframes} = props const sheetObjectAddress = props.viewModel.sheetObject.address
return usePrism(() => {
const cur = aggregateKeyframes[index] const cur = aggregateKeyframes[index]
const next = aggregateKeyframes[index + 1] const next = aggregateKeyframes[index + 1]
@ -187,24 +188,24 @@ function useAggregateKeyframeEditorUtils(
const aggregatedConnections: AggregatedKeyframeConnection[] = !connected const aggregatedConnections: AggregatedKeyframeConnection[] = !connected
? [] ? []
: cur.keyframes.map(({kf, track}, i) => ({ : cur.keyframes.map(({kf, track}, i) => ({
...props.viewModel.sheetObject.address, ...sheetObjectAddress,
trackId: track.id, trackId: track.id,
left: kf, left: kf,
right: next.keyframes[i].kf, right: next.keyframes[i].kf,
})) }))
const {projectId, sheetId} = props.viewModel.sheetObject.address const {projectId, sheetId} = sheetObjectAddress
const selectedConnections = prism const selectedConnections = prism
.memo( .memo(
'selectedConnections', 'selectedConnections',
() => () =>
selectedKeyframeConnections( selectedKeyframeConnections(
props.viewModel.sheetObject.address.projectId, sheetObjectAddress.projectId,
props.viewModel.sheetObject.address.sheetId, sheetObjectAddress.sheetId,
props.selection, selection,
), ),
[projectId, sheetId, props.selection], [projectId, sheetId, selection],
) )
.getValue() .getValue()
@ -215,7 +216,7 @@ function useAggregateKeyframeEditorUtils(
) )
return {cur, connected, isAggregateEditingInCurvePopover, allConnections} return {cur, connected, isAggregateEditingInCurvePopover, allConnections}
}, []) }, [index, aggregateKeyframes, selection, sheetObjectAddress])
} }
const AggregateCurveEditorPopover: React.FC< const AggregateCurveEditorPopover: React.FC<

View file

@ -0,0 +1,22 @@
import {useEffect, useState} from 'react'
/**
* Little utility hook that refreshes a react element every `ms` milliseconds. Use
* it to debug whether the props of the element, or the return values of its hooks
* are getting properly updated.
*
* @param ms - interval in milliseconds
*/
export default function useDebugRefreshEvery(ms: number = 500) {
const [_, setState] = useState(0)
useEffect(() => {
const interval = setInterval(() => {
setState((i) => i + 1)
}, ms)
return () => {
clearInterval(interval)
}
}, [])
}