UNPKG

react-native-filament

Version:

A real-time physically based 3D rendering engine for React Native

32 lines (29 loc) 1.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useWorkletCallback = useWorkletCallback; var _reactNativeWorkletsCore = require("react-native-worklets-core"); var _useFilamentContext = require("./useFilamentContext"); var _ErrorUtils = require("../ErrorUtils"); var _react = require("react"); /** * Creates a callback that can be executed in he separate worklet thread of the engine. */ function useWorkletCallback(callback) { const { workletContext } = (0, _useFilamentContext.useFilamentContext)(); // Note: from react-native-worklets-core/useWorklet // As we want to wrap using `wrapWithErrorHandler` the dependencies must be captured from the // callback, not from the wrapper. // As a dependency for this use-memo we use all of the values captured inside the worklet, // as well as the unique context name. const dependencies = [...(0, _reactNativeWorkletsCore.getWorkletDependencies)(callback)]; return (0, _react.useMemo)(() => { return workletContext.createRunAsync((0, _ErrorUtils.wrapWithErrorHandler)(callback)); }, // eslint-disable-next-line react-hooks/exhaustive-deps dependencies); } //# sourceMappingURL=useWorkletCallback.js.map