1 line
1.9 KiB
Plaintext
1 line
1.9 KiB
Plaintext
{"version":3,"file":"transform-value.mjs","sources":["../../../src/value/transform-value.ts"],"sourcesContent":["import { MotionValue, collectMotionValues, motionValue } from \".\"\nimport { subscribeValue } from \"./subscribe-value\"\n\nexport type TransformInputRange = number[]\nexport type SingleTransformer<I, O> = (input: I) => O\nexport type MultiTransformer<I, O> = (input: I[]) => O\nexport type ValueTransformer<I, O> =\n | SingleTransformer<I, O>\n | MultiTransformer<I, O>\n\n/**\n * Create a `MotionValue` that transforms the output of other `MotionValue`s by\n * passing their latest values through a transform function.\n *\n * Whenever a `MotionValue` referred to in the provided function is updated,\n * it will be re-evaluated.\n *\n * ```jsx\n * const x = motionValue(0)\n * const y = transformValue(() => x.get() * 2) // double x\n * ```\n *\n * @param transformer - A transform function. This function must be pure with no side-effects or conditional statements.\n * @returns `MotionValue`\n *\n * @public\n */\nexport function transformValue<O>(transform: () => O): MotionValue<O> {\n const collectedValues: MotionValue[] = []\n\n /**\n * Open session of collectMotionValues. Any MotionValue that calls get()\n * inside transform will be saved into this array.\n */\n collectMotionValues.current = collectedValues\n const initialValue = transform()\n collectMotionValues.current = undefined\n\n const value = motionValue(initialValue)\n\n subscribeValue(collectedValues, value, transform)\n\n return value\n}\n"],"names":[],"mappings":";;;AAUA;;;;;;;;;;;;;;;;AAgBG;AACG,SAAU,cAAc,CAAI,SAAkB,EAAA;IAChD,MAAM,eAAe,GAAkB,EAAE,CAAA;AAEzC;;;AAGG;AACH,IAAA,mBAAmB,CAAC,OAAO,GAAG,eAAe,CAAA;AAC7C,IAAA,MAAM,YAAY,GAAG,SAAS,EAAE,CAAA;AAChC,IAAA,mBAAmB,CAAC,OAAO,GAAG,SAAS,CAAA;AAEvC,IAAA,MAAM,KAAK,GAAG,WAAW,CAAC,YAAY,CAAC,CAAA;AAEvC,IAAA,cAAc,CAAC,eAAe,EAAE,KAAK,EAAE,SAAS,CAAC,CAAA;AAEjD,IAAA,OAAO,KAAK,CAAA;AAChB;;;;"} |