From e4227066d4bb9609a8894f65ca6c4ae2e1aafb3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20=C5=BBelawski?= Date: Mon, 3 Feb 2025 17:50:50 +0100 Subject: [PATCH] chore: cleanup --- .../src/worklets/initializers.ts | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/packages/react-native-worklets/src/worklets/initializers.ts b/packages/react-native-worklets/src/worklets/initializers.ts index ff474533c7f..556ed245d9f 100644 --- a/packages/react-native-worklets/src/worklets/initializers.ts +++ b/packages/react-native-worklets/src/worklets/initializers.ts @@ -31,6 +31,25 @@ function overrideLogFunctionImplementation() { }); } +// Register logger config and replace the log function implementation in +// the React runtime global scope +registerLoggerConfig(DEFAULT_LOGGER_CONFIG); +overrideLogFunctionImplementation(); + +// this is for web implementation +if (SHOULD_BE_USE_WEB) { + global._WORKLET = false; + global._log = console.log; + global._getAnimationTimestamp = () => performance.now(); +} else { + // Register WorkletsError and logger config in the UI runtime global scope. + // (we are using `executeOnUIRuntimeSync` here to make sure that the changes + // are applied before any async operations are executed on the UI runtime) + executeOnUIRuntimeSync(registerWorkletsError); + executeOnUIRuntimeSync(registerLoggerConfig)(DEFAULT_LOGGER_CONFIG); + executeOnUIRuntimeSync(overrideLogFunctionImplementation)(); +} + // callGuard is only used with debug builds export function callGuardDEV( fn: (...args: Args) => ReturnValue, @@ -62,25 +81,6 @@ export function setupCallGuard() { }; } -// Register logger config and replace the log function implementation in -// the React runtime global scope -registerLoggerConfig(DEFAULT_LOGGER_CONFIG); -overrideLogFunctionImplementation(); - -// this is for web implementation -if (SHOULD_BE_USE_WEB) { - global._WORKLET = false; - global._log = console.log; - global._getAnimationTimestamp = () => performance.now(); -} else { - // Register WorkletsError and logger config in the UI runtime global scope. - // (we are using `executeOnUIRuntimeSync` here to make sure that the changes - // are applied before any async operations are executed on the UI runtime) - executeOnUIRuntimeSync(registerWorkletsError); - executeOnUIRuntimeSync(registerLoggerConfig)(DEFAULT_LOGGER_CONFIG); - executeOnUIRuntimeSync(overrideLogFunctionImplementation)(); -} - /** * Currently there seems to be a bug in the JSI layer which causes a crash when * we try to copy some of the console methods, i.e. `clear` or `dirxml`.