UNPKG

react-native-filament

Version:

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

40 lines (39 loc) 1.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.withCleanupScope = withCleanupScope; var _reactNative = require("react-native"); /** * Operations that are releasing memory from JS should be executed after cleanup functions * that are still operating on the resource. * For example in a cleanup you might remove an asset from the scene, but you also want to release the memory of the asset. * The memory release() function call should be wrapped with withCleanupScope. * * @note You probably don't need to call this yourself! * * @example * * ```ts * useEffect(() => { * const asset = // ... acquire some resources * * return withCleanupScope(() => { * asset.release() * }) * }) * ``` */ function withCleanupScope(cleanupFunction) { return () => { // runAfterInteractions to make sure its called after all children have run their cleanup and all interactions are done _reactNative.InteractionManager.runAfterInteractions(() => { // Cleanup in worklets context, as cleanup functions might also use the worklet context // and we want to queue our cleanup after all other worklets have run setTimeout(() => { cleanupFunction(); }, 0); }); }; } //# sourceMappingURL=withCleanupScope.js.map