{"version":3,"names":["useEffect","startMapper","stopMapper","useSharedValue","shouldBeUseWeb","useAnimatedReaction","prepare","react","dependencies","previous","inputs","Object","values","__closure","_dependencies","length","undefined","__workletHash","push","fun","input","value","mapperId"],"sources":["useAnimatedReaction.ts"],"sourcesContent":["'use strict';\nimport { useEffect } from 'react';\nimport type { WorkletFunction } from '../commonTypes';\nimport { startMapper, stopMapper } from '../core';\nimport type { DependencyList } from './commonTypes';\nimport { useSharedValue } from './useSharedValue';\nimport { shouldBeUseWeb } from '../PlatformChecker';\n\n/**\n * Lets you to respond to changes in a [shared value](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/glossary#shared-value). It's especially useful when comparing values previously stored in the shared value with the current one.\n *\n * @param prepare - A function that should return a value to which you'd like to react.\n * @param react - A function that reacts to changes in the value returned by the `prepare` function.\n * @param dependencies - an optional array of dependencies. Only relevant when using Reanimated without the Babel plugin on the Web.\n * @see https://docs.swmansion.com/react-native-reanimated/docs/advanced/useAnimatedReaction\n */\n// @ts-expect-error This overload is required by our API.\nexport function useAnimatedReaction(\n prepare: () => PreparedResult,\n react: (prepared: PreparedResult, previous: PreparedResult | null) => void,\n dependencies?: DependencyList\n): void;\n\nexport function useAnimatedReaction(\n prepare: WorkletFunction<[], PreparedResult>,\n react: WorkletFunction<\n [prepare: PreparedResult, previous: PreparedResult | null],\n void\n >,\n dependencies?: DependencyList\n) {\n const previous = useSharedValue(null);\n\n let inputs = Object.values(prepare.__closure ?? {});\n\n if (shouldBeUseWeb()) {\n if (!inputs.length && dependencies?.length) {\n // let web work without a Reanimated Babel plugin\n inputs = dependencies;\n }\n }\n\n if (dependencies === undefined) {\n dependencies = [\n ...Object.values(prepare.__closure ?? {}),\n ...Object.values(react.__closure ?? {}),\n prepare.__workletHash,\n react.__workletHash,\n ];\n } else {\n dependencies.push(prepare.__workletHash, react.__workletHash);\n }\n\n useEffect(() => {\n const fun = () => {\n 'worklet';\n const input = prepare();\n react(input, previous.value);\n previous.value = input;\n };\n const mapper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