stop inlining throttled function to keep them stable

This commit is contained in:
dwelle 2023-08-10 23:45:01 +02:00
parent bf3fac68db
commit aedcee6c7e

View File

@ -1048,6 +1048,15 @@ const _renderStaticScene = ({
}); });
}; };
/** throttled to animation framerate */
const renderInteractiveSceneThrottled = throttleRAF(
(config: InteractiveSceneRenderConfig) => {
const ret = _renderInteractiveScene(config);
config.callback?.(ret);
},
{ trailing: true },
);
export const renderInteractiveScene = < export const renderInteractiveScene = <
U extends typeof _renderInteractiveScene, U extends typeof _renderInteractiveScene,
T extends boolean = false, T extends boolean = false,
@ -1056,16 +1065,7 @@ export const renderInteractiveScene = <
throttle?: T, throttle?: T,
): T extends true ? void : ReturnType<U> => { ): T extends true ? void : ReturnType<U> => {
if (throttle) { if (throttle) {
/** throttled to animation framerate */ renderInteractiveSceneThrottled(renderConfig);
const renderFuncThrottled = throttleRAF(
(config) => {
const ret = _renderInteractiveScene(config);
config.callback?.(ret);
},
{ trailing: true },
);
renderFuncThrottled(renderConfig);
return undefined as T extends true ? void : ReturnType<U>; return undefined as T extends true ? void : ReturnType<U>;
} }
const ret = _renderInteractiveScene(renderConfig); const ret = _renderInteractiveScene(renderConfig);
@ -1073,20 +1073,20 @@ export const renderInteractiveScene = <
return ret as T extends true ? void : ReturnType<U>; return ret as T extends true ? void : ReturnType<U>;
}; };
/** throttled to animation framerate */
const renderStaticSceneThrottled = throttleRAF(
(config: StaticSceneRenderConfig) => {
_renderStaticScene(config);
},
{ trailing: true },
);
export const renderStaticScene = ( export const renderStaticScene = (
renderConfig: StaticSceneRenderConfig, renderConfig: StaticSceneRenderConfig,
throttle?: boolean, throttle?: boolean,
) => { ) => {
if (throttle) { if (throttle) {
/** throttled to animation framerate */ renderStaticSceneThrottled(renderConfig);
const renderFuncThrottled = throttleRAF(
(config) => {
_renderStaticScene(config);
},
{ trailing: true },
);
renderFuncThrottled(renderConfig);
return; return;
} }