-
-
Notifications
You must be signed in to change notification settings - Fork 830
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
24f4ae4
commit 75f3296
Showing
4 changed files
with
51 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,21 @@ | ||
import type { MotionValue } from "." | ||
import { collectMotionValues, type MotionValue } from "." | ||
import { useCombineMotionValues } from "./use-combine-values" | ||
|
||
let collectMotionValues: MotionValue[] | undefined = undefined | ||
|
||
export function useComputed<O>(compute: () => O): MotionValue<O> { | ||
collectMotionValues = [] | ||
/** | ||
* Open session of collectMotionValues. Any MotionValue that calls get() | ||
* will be saved into this array. | ||
*/ | ||
collectMotionValues.current = [] | ||
|
||
compute() | ||
const value = useCombineMotionValues(collectMotionValues, compute) | ||
collectMotionValues = undefined | ||
|
||
const value = useCombineMotionValues(collectMotionValues.current, compute) | ||
|
||
/** | ||
* Synchronously close session of collectMotionValues. | ||
*/ | ||
collectMotionValues.current = undefined | ||
|
||
return value | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters